首页 > 解决方案 > 弹性搜索查询无法运行

问题描述

我对弹性搜索很陌生,想在匹配条件时为特定字段的所有值编写查询,我尝试构建以下查询,基本上它来自 Kibana,我复制了请求正文并尝试运行ES 节点。

curl -XGET "http://localhost:9200/test_index/_search?pretty" -H 'Content-Type: application/json' -d'
 {
  "version": true,
  "size": 500,
  "sort": [
    {
      "actual_start": {
        "order": "desc",
        "unmapped_type": "boolean"
      }
    }
  ],
  "_source": {
    "excludes": []
  },
  "aggs": {
    "2": {
      "date_histogram": {
        "field": "actual_start",
        "interval": "5m",
        "time_zone": "Asia/Kolkata",
        "min_doc_count": 1
      }
    }
  },
  "stored_fields": [
    "*"
  ],
  "script_fields": {},
  "docvalue_fields": [
    {
      "field": "Updated",
      "format": "date_time"
    },
    {
      "field": "actual_end",
      "format": "date_time"
    },
    {
      "field": "actual_start",
      "format": "date_time"
    },
    {
      "field": "created_on",
      "format": "date_time"
    },
    {
      "field": "planned_start",
      "format": "date_time"
    }
  ],
  "query": {
    "bool": {
      "must": [
        {
          "match_all": {}
        },
        {
          "exists": {
            "field": "Number"
          }
        },
        {
          "match_phrase": {
            "change_manager_group": {
              "query": "Change Managers - 2"
            }
          }
        },
        {
          "range": {
            "actual_start": {
              "gte": 1556028682454,
              "lte": 1556043082454,
              "format": "epoch_millis"
            }
          }
        }
      ],
      "filter": [],
      "should": [],
      "must_not": []
    }
  }'

我收到以下错误,我相信这与格式化查询有关

{
  "error" : {
    "root_cause" : [
      {
        "type" : "json_e_o_f_exception",
        "reason" : "Unexpected end-of-input: expected close marker for Object (start marker at [Source: org.elasticsearch.transport.netty4.ByteBufStreamInput@177d880d; line: 2, column: 1])\n at [Source: org.elasticsearch.transport.netty4.ByteBufStreamInput@177d880d; line: 85, column: 1448]"
      }
    ],
    "type" : "json_e_o_f_exception",
    "reason" : "Unexpected end-of-input: expected close marker for Object (start marker at [Source: org.elasticsearch.transport.netty4.ByteBufStreamInput@177d880d; line: 2, column: 1])\n at [Source: org.elasticsearch.transport.netty4.ByteBufStreamInput@177d880d; line: 85, column: 1448]"
  },
  "status" : 500
}

我在这里做错了什么?

标签: elasticsearchnested

解决方案


弹性搜索抱怨您的 json 字符串末尾缺少花括号。您可以使用许多(哦,这么多)在线 json 验证器中的任何一个来验证您的 json 架构,例如https://jsonlint.com/


推荐阅读