如何在ElasticSearch中对_search查询使用“explain”

时间:2016-09-02 17:54:30

标签: elasticsearch

我正在使用ElasticSearch 2.3.3。

我有以下映射:

"mappings": {
    "entries": {
        "dynamic": "strict",
        "properties": {
            "Data": {
                "properties": {
                    "FirstName": {
                        "type": "string",
                        "index": "not_analyzed"
                    }
                }
            }
        }
    }
}

我有以下查询:

POST /frm4356/entries/_search
{
    "query" : {
        "match" : {"Data.FirstName" : "BBB"}
    }
}

哪种方法正常并产生以下响应:

{
  "took": 1,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "failed": 0
  },
  "hits": {
    "total": 1,
    "max_score": 1,
    "hits": [
      {
        "_index": "frm4356_v3",
        "_type": "entries",
        "_id": "57c867715f7ecd2a78610ec6",
        "_score": 1,
        "_source": {
          "Data": {
            "FirstName": "BBB"
          }
        }
      }
    ]
  }
}

我试图使用“Explain API”,但失败了。

以下不起作用:

尝试#1

POST /frm4356/entries/_explain
{
    "query" : {
    "match" : {"Data.FirstName" : "BBB"}
    }
}

尝试#2:

POST /frm4356/entries/_search
{
    "explain" : true,
    "query" : {
    "match" : {"Data.FirstName" : "BBB"}
    }
}

在这两种情况下,我都会收到这样的答复:

{
   "error": {
      "root_cause": [
         {
            "type": "strict_dynamic_mapping_exception",
            "reason": "mapping set to strict, dynamic introduction of [query] within [entries] is not allowed"
         }
      ],
      "type": "strict_dynamic_mapping_exception",
      "reason": "mapping set to strict, dynamic introduction of [query] within [entries] is not allowed"
   },
   "status": 400
}

我做错了什么?我想看看查询的解释。

2 个答案:

答案 0 :(得分:1)

尝试这样的事情:

GET /blog/post/_validate/query?explain
{
  "query": {
    "match": {
      "title": "Smith"
    }
  }
}

Source

答案 1 :(得分:0)

Here's Explain API的官方文档。

看起来你错过了那里的_id。

POST /frm4356/entries/57c867715f7ecd2a78610ec6/_explain
{
  "query": {
    "match": {
      "Data.FirstName": "BBB"
    }
  }
}