gpt4 book ai didi

elasticsearch - 对所有数组元素的elasticsearch查询

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

在以下查询中,如何搜索具有所有指定标签的文档?我尝试了minimum_should_match和“execution”:“and”,但我的查询均不支持它们。

GET products/fashion/_search
{
"query": {
"constant_score": {
"filter" : {
"bool" : {
"must" : [
{"terms" : {
"tags" : ["gucci", "dresses"]
}},
{"range" : {
"price.value" : {
"gte" : 100,
"lt" : 1000
}
}}
]
}
}
}
},
"sort": { "date": { "order": "desc" }}
}

======更新

我找到了建立查询的方法。任务是在elasticsearch中重现以下mongodb查询:
{
"tags": {
"$all":["gucci","dresses"]
},
"price.value":{"$gte":100,"$lte":1000}
}

这是我的elasticsearch查询
GET products/fashion/_search
{
"query": {
"bool" : {
"filter" : [
{"term" : {
"tags" : "gucci"
}},
{"term" : {
"tags" : "dresses"
}},
{"range" : {
"price.value" : {
"gte" : 100,
"lt" : 1000
}
}}
]
}
}
}

最佳答案

您是否为索引定义了映射?默认情况下,Elasticsearch将分析字符串字段。如果要像上面一样查找确切的术语,则需要在映射中将它们指定为not_analyzed

https://www.elastic.co/guide/en/elasticsearch/guide/current/_finding_exact_values.html#_term_filter_with_text

关于elasticsearch - 对所有数组元素的elasticsearch查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41333475/

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