0

我尝试通过一个名为 unit 的字段查询项目,该字段区分大小写(如 kWh),但我的术语查询仅在我查询 kwh(小写 W)时匹配。我在文档中看到的是该术语应该是区分大小写的正确术语,所以我不确定我做错了什么。

## Create an item
curl -X POST "localhost:9200/my_index/my_type/my_id" -H 'Content-Type: application/json' -d'{"point_name" : "my_point_name", "unit" : "kWh"}'
=> {"_index":"my_index","_type":"my_type","_id":"my_id","_version":1,"result":"created","_shards":{"total":2,"successful":1,"failed":0},"created":true}

## Try to query it by unit with exact match (kWh)
curl -X GET "localhost:9200/my_index/my_type/_search" -H 'Content-Type: application/json' -d'{"query" : { "bool" : {"must" : [{ "term" : {"unit" : "kWh"}}]}}}'
=> {"took":36,"timed_out":false,"_shards":{"total":5,"successful":5,"skipped":0,"failed":0},"hits":{"total":0,"max_score":null,"hits":[]}}

## Query with lower case unit kwh
curl -X GET "localhost:9200/my_index/my_type/_search" -H 'Content-Type: application/json' -d'{"query" : { "bool" : {"must" : [{ "term" : {"unit" : "kwh"}}]}}}'
=> {"took":12,"timed_out":false,"_shards":{"total":5,"successful":5,"skipped":0,"failed":0},"hits":{"total":1,"max_score":0.2876821,"hits":[{"_index":"my_index","_type":"my_type","_id":"my_id","_score":0.2876821,"_source":{"point_name" : "my_point_name", "unit" : "kWh"}}]}}

我不想在这里使用 match,因为我也通过其他字段创建了这些查询,并且我想确保完全匹配的行为。谁能指出我的查询是如何正确的以及为什么这个术语查询不起作用?

我正在使用这个 dockerimage 作为我的服务器:

docker.elastic.co/elasticsearch/elasticsearch:6.2.4

4

0 回答 0