为什么Elasticsearch查询不返回记录?

时间:2019-08-12 07:46:44

标签: elasticsearch

我有一个小的Elasticsearch集群。一条记录如下:

        "hits" : [
          {
            "_index" : "readiness",
            "_type" : "council_doc",
            "_id" : "4sqzhGwBkqm_VQwAkam8",
            "_score" : 6.4425545,
            "_source" : {
              "code" : "E06000001",
              "council_name" : "Hartlepool",
              "council_response" : "Refused",
              "response_type" : "3"
            }
          }
        ]

这是由以下Curl查询产生的:

{
  "query": { "match": { "council_name": "Hartlepool" } }
}

如您所见,其中一个字段称为“代码”,当我尝试运行查询时,获得相同的结果,但是按以下代码字段进行搜索不会产生任何结果:

 {
      "query": { "match": { "code": "E06000001" } }
    }

我没有收到错误消息,只是得到了零点击。我很迷惑,有人可以帮忙吗?代码字段和Council_name字段都具有相同的映射属性:keyword。

映射为:

{
  "readiness" : {
    "mappings" : {
      "properties" : {
        "council_name" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "council_response" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "response_type" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "code" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        }
      }
    }
  }
}

以下是我所谈论的例子:

curl -X GET "localhost:9200/readiness/_search?pretty" -H 'Content-Type: application/json' -d'
> {
>   "query": { "match": { "code.keyword": "E06000001" } }
> }
> '
{
  "took" : 2,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 0,
      "relation" : "eq"
    },
    "max_score" : null,
    "hits" : [ ]
  }
}

1 个答案:

答案 0 :(得分:0)

根据您的映射,您的查询应该可以工作(我可以复制并且可以工作)。您可能还想尝试以下查询(即在.keyword子字段上):

{
  "query": { "match": { "code.keyword": "E06000001" } }
}