ElasticSearch- [exists]查询不支持弹性搜索2.3

时间:2017-01-06 06:59:03

标签: elasticsearch elasticsearch-2.0

POST /ankita-inex/my_type/_bulk

{ "index": { "_id": 1 }}
{ "title": "The quick brown fox" }

{ "index": { "_id": 2 }}
{ "title": "The quick brown fox jumps over the lazy dog" }

{ "index": { "_id": 3 }}
{ "title": "The quick brown fox jumps over the quick dog" }

{ "index": { "_id": 4 }}
{ "title": "Brown fox brown dog" }

这已成功发布但我想使用存在查询来使用MissingQuery

GET /ankita-inex/my_type/_search
{
"query" : {

    "bool": {

        "must": {

           "exists" : {

               "index" : "4" 
           }
        }

    }
} }


{

"error": 
 {

  "root_cause": [

     {

        "type": "query_parsing_exception",

        "reason": "[exists] query does not support [index]",

        "index": "ankita-inex",

        "line": 6,

        "col": 20

     }

  ],

  "type": "search_phase_execution_exception",

  "reason": "all shards failed",

  "phase": "query",

  "grouped": true,

  "failed_shards": [

     {

        "shard": 0,

        "index": "ankita-inex",

        "node": "pbwST3JVSlq3sPqBgWoAVg",

        "reason": {

           "type": "query_parsing_exception",

           "reason": "[exists] query does not support [index]",

           "index": "ankita-inex",

           "line": 6,

           "col": 20

        }

     }

  ]

},

"status": 400
}

1 个答案:

答案 0 :(得分:0)

exists查询是查找具有给定命名字段的文档,而不是用于检查确切的值。如果您必须查看包含_id: 4的文档是否存在,您可以这样做:

POST /ankita-inex/my_type/_search
{
"query" : {

    "bool": {

        "must": {

           "term" : {

               "_id" : "4" 
           }
        }

    }
} }

或者只是这样:

GET /ankita-inex/my_type/4

这将返回文件(如果存在)