我想您的字段已经过分析,这是elasticsearch中字符串字段的默认设置。结果,当它被索引时,它不是被索引为一个术语“ update-
time”,而是被索引为两个术语:“ update”和“
time”。这就是为什么您的术语搜索找不到该术语的原因。如果您的字段将始终包含必须完全匹配的值,那么最好在映射中将此类字段定义为未分析。您可以通过使用新映射重新创建索引来做到这一点:
curl -XPUT http://localhost:9200/your-index -d '{ "mappings" : { "your-type" : { "properties" : { "field" : { "type": "string", "index" : "not_analyzed" } } } }}'curl -XPUT http://localhost:9200/your-index/your-type/1 -d '{ "field" : "update-time"}'curl -XPOST http://localhost:9200/your-index/your-type/_search -d'{ "filter": { "term": { "field": "update-time" } }}'另外,如果您希望在基于此字段查找记录时有一定的灵活性,则可以保持对该字段的分析并使用文本查询:
curl -XPOST http://localhost:9200/your-index/your-type/_search -d'{ "query": { "text": { "field": "update-time" } }}'请记住,如果对您的字段进行了分析,那么只需搜索单词“ update”或单词“ time”,即可找到该记录。



