【问题标题】:How to use "explain" for _search queries in ElasticSearch如何在 ElasticSearch 中对 _search 查询使用“解释”
【发布时间】:2016-09-03 09:36:30
【问题描述】:

我正在使用 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"
          }
        }
      }
    ]
  }
}

我尝试使用“解释 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
}

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

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    试试这样的:

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

    Source

    【讨论】:

      【解决方案2】:

      Here's Explain API 的官方文档。

      您好像错过了那里的 _id。

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-10-02
        • 1970-01-01
        相关资源
        最近更新 更多