【问题标题】:ElasticSearch - failed to parse search source. expected field name but got [START_OBJECT]ElasticSearch - 无法解析搜索源。预期的字段名称,但得到 [START_OBJECT]
【发布时间】:2016-07-28 10:58:23
【问题描述】:

我无法弄清楚我的 ES 查询出了什么问题。 我想过滤特定字段,并按其他字段排序。

请求:

GET /_search
{
    "query" : {
        "term": {
          "_type" : "monitor"
        },
        "filtered" : {
            "filter" : { "term" : { "ProcessName" : "myProc" }}
        }
    },
    "sort": { "TraceDateTime": { "order": "desc", "ignore_unmapped": "true" }}
}

回应:

{
   "error": {
      "root_cause": [
         {
            "type": "parse_exception",
            "reason": "failed to parse search source. expected field name but got [START_OBJECT]"
         }
      ],
      "type": "search_phase_execution_exception",
      "reason": "all shards failed",
      "phase": "query",
      "grouped": true,
      "failed_shards": [
         {
            "shard": 0,
            "index": ".kibana",
            "node": "94RPDCjhQh6eoTe6XoRmSg",
            "reason": {
               "type": "parse_exception",
               "reason": "failed to parse search source. expected field name but got [START_OBJECT]"
            }
         }
      ]
   },
   "status": 400
}

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    您的查询中有语法错误,您需要将两个 term 查询包含在一个 bool/must 复合查询中,它需要是这样的:

    POST /_search
    {
      "query": {
        "filtered": {
          "filter": {
            "bool": {
              "must": [
                {
                  "term": {
                    "ProcessName": "myProc"
                  }
                },
                {
                  "term": {
                    "_type": "monitor"
                  }
                }
              ]
            }
          }
        }
      },
      "sort": {
        "TraceDateTime": {
          "order": "desc",
          "ignore_unmapped": "true"
        }
      }
    }
    

    PS:在查询中发送有效负载时始终使用 POST。

    【讨论】:

    • 嗨 val,现在我收到了这样的回复:{ "took": 1, "timed_out": false, "_shards": { "total": 2, "successful": 2, " failed": 0 }, "hits": { "total": 0, "max_score": null, "hits": [] } } 虽然“ProcessName”值确实存在。如果我消除第一个术语 - 它会找到所有文档。
    • 尝试使用小写的myproc。这很可能是因为您的 ProcessName 字段已被分析。
    • 工作!谢谢大师!
    • 另一个小问题:文档说我应该使用 get 进行搜索:elastic.co/guide/en/elasticsearch/guide/current/_sorting.html 我们为什么要使用 POST ?
    • 文档并不总是 100% 正确。看到这个:stackoverflow.com/questions/34795053/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-15
    • 2016-12-17
    • 1970-01-01
    • 2020-11-16
    相关资源
    最近更新 更多