【发布时间】:2020-06-15 07:55:37
【问题描述】:
我有 2 个索引、城市和地点。 Places 有这样的映射:
{
"mappings": {
"properties": {
"cityId": {
"type": "integer"
},
"cityName": {
"type": "text"
},
"placeName": {
"type": "text"
},
"status": {
"type": "keyword"
},
"category": {
"type": "keyword"
},
"reviews": {
"properties": {
"rating": {
"type": "long"
},
"comment": {
"type": "keyword"
},
"user": {
"type": "nested"
}
}
}
}
}
}
而城市是索引映射如下:
{
"mappings": {
"properties": {
"state": {
"type": "keyword"
},
"postal": {
"type": "keyword"
},
"phone": {
"type": "keyword"
},
"email": {
"type": "keyword"
},
"notes": {
"type": "keyword"
},
"status": {
"type": "keyword"
},
"cityName": {
"type": "text"
},
"website": {
"type": "keyword"
},
"cityId": {
"type": "integer"
}
}
}
}
最初,我们有一个文档,其中城市嵌入了地点,但我在搜索嵌套地点数组时遇到问题,因此我将结构更改为这样,我希望能够在单个查询中模糊搜索 cityName 和 placeName。我有一个城市,其名称中包含 Welder's 一词,并且同一位置内的某些地方的名称中包含 Welder's 一词,其类型为:文本。但是,当搜索welder 时,以下两个查询都不会返回这些文档,而搜索welders ORwelder's 会返回这些文档。我不确定为什么焊机与焊机*不匹配。在创建两个索引的过程中我没有指定任何分析器,我也没有在查询中明确定义它,任何人都可以帮助我解决这个查询,所以它的行为符合预期:
查询 1:索引 = 地点
{
"query": {
"bool": {
"should": [
{
"match": {
"placeName": {
"query": "welder",
"fuzziness": 20
}
}
},
{
"match": {
"cityName": {
"query": "welder",
"fuzziness": 20
}
}
}
]
}
}
}
查询 2:索引 = 地点
{
"query": {
"match": {
"placeName": {
"query": "welder",
"fuzziness": 20
}
}
}
}
任何人都可以发布一个查询,当传递一个单词welder时,会返回他们名字中包含Welder的文档(也应该适用于类似这些的其他术语,这只是一个示例)
编辑 1: 这是我希望上面发布的任何查询返回的示例地点文档:
{
cityId: 29,
placeName: "Welder's Garage Islamabad",
cityName: "Islamabad",
status: "verified",
category: null,
reviews: []
}
【问题讨论】:
-
请添加应在查询中返回的示例文档
-
嗨@jaspreetchahal 我添加了一个示例文档,请检查他上面的原始问题。谢谢
标签: elasticsearch elastic-stack elasticsearch-5 mongoosastic