gpt4 book ai didi

elasticsearch - elasticsearch查找包含值子字符串的字段和包含值的字段

转载 作者:行者123 更新时间:2023-12-03 02:15:49 25 4
gpt4 key购买 nike

我正在尝试实现一个下拉搜索系统,因此,如果我搜索“沃尔姆”,我将获得“沃尔玛”的结果。
此查询将起作用:

GET /indexname*/_search
{
"size":0,

"aggs": {
"by_filter": {
"terms": {
"field": "store_name.keyword",
"size":1000
},
"aggs": {
"doc": {
"top_hits": {
"size": 1
}
}
}
}
},

"query": {
"bool": {
"must": [
{
"query_string": {
"query": "store_name: 'walmart' AND (source: 'smartpakequine') AND product_gap.keyword: 'yes'"
}
},
{
"range": {
"@timestamp": {
"format": "date",
"gte": "2020-08-25",
"lte": "2020-08-27"
}
}
}
]
}
},

"sort": { "assortment_score": { "order": "desc" } }

}
但是如果我为我的query_string包括部分字符串,例如:
"query": "store_name: 'walm' AND (source: 'smartpakequine') AND product_gap.keyword: 'yes'"
它将返回零结果。如果我将查询更改为仅包含正则表达式,如下所示:
    "query": {
"bool": {
"must": [
{
"regexp": {
"store_name": "walmart.*"
},
}
]
}
}
它有效,但随后我无法包含用于搜索其他参数的查询字符串。与通配符搜索相同,我只能包含通配符搜索,不能再使用原始的query_string了。有什么办法可以告诉我的query_string包括store_name的部分子字符串结果?
"query": "store_name: 'walm' AND (source: 'smartpakequine') AND product_gap.keyword: 'yes'"

最佳答案

添加带有索引数据,搜索查询和搜索结果的工作示例。
请引用此ES official documentation以获取有关查询字符串查询的详细说明
索引数据:

{
"store_name": "wallmart",
"product_gap":"yes"
}

{
"store_name": "wallm",
"product_gap":"yes"
}
搜索查询:
{
"query": {
"query_string":
{ "fields": ["store_name", "product_gap"],
"query": "Wallm* AND yes"
}
}
}
搜索结果:
"hits": [
{
"_index": "test",
"_type": "_doc",
"_id": "2",
"_score": 1.1823215,
"_source": {
"store_name": "wallm",
"product_gap": "yes"
}
},
{
"_index": "test",
"_type": "_doc",
"_id": "1",
"_score": 1.1823215,
"_source": {
"store_name": "wallmart",
"product_gap": "yes"
}
}
]

关于elasticsearch - elasticsearch查找包含值子字符串的字段和包含值的字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63623425/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com