我需要向Elasticsearch数据库解释术语查询的一些奇怪行为,该数据库包含字符串中的数字部分。查询非常简单:
{
"query": {
"bool": {
"should": [
{
"term": {
"address.street": "8 kvetna"
}
}
]
}
}
}问题是术语8 kvetna返回空结果。我试着用_analyze来制作像8,k,kv,kve这样的常规标记.而且,我很确定数据库中有一个值8 kvetna。以下是该字段的映射:
{
"settings": {
"index": {
"refresh_interval": "1m",
"number_of_shards": "1",
"number_of_replicas": "1",
"analysis": {
"filter": {
"autocomplete_filter": {
"type": "edge_ngram",
"min_gram": "1",
"max_gram": "20"
}
},
"analyzer": {
"autocomplete": {
"filter": [
"lowercase",
"asciifolding",
"autocomplete_filter"
],
"type": "custom",
"tokenizer": "standard"
}
"default": {
"filter": [
"lowercase",
"asciifolding"
],
"type": "custom",
"tokenizer": "standard"
}
}
}
}
},
"mappings": {
"doc": {
"dynamic": "strict",
"_all": {
"enabled": false
},
"properties": {
"address": {
"properties": {
"city": {
"type": "text",
"analyzer": "autocomplete"
},
"street": {
"type": "text",
"analyzer": "autocomplete"
}
}
}
}
}
}
}是什么导致了这个奇怪的结果?我不明白。谢谢你的帮助。
发布于 2019-06-17 12:58:30
到目前为止开局很好!唯一的问题是,您使用的是term查询,而应该使用match查询。term查询将尝试对8 kvetna进行精确匹配,这不是您想要的。以下查询将有效:
{
"query": {
"bool": {
"should": [
{
"match": { <--- change this
"address.street": "8 kvetna"
}
}
]
}
}
}https://stackoverflow.com/questions/56631697
复制相似问题