gpt4 book ai didi

elasticsearch - Elastic Search 1.7.3嵌套过滤器:匹配对象数组中的术语

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

我试图在我的elasticsearch中查询以下文档:

"amenity": [
"Free Wifi",
"Free Breakfast",
"Veg Only",
"Swimming Pool",
"Newspaper",
"Bar",
"Credit Card",
"Pickup & Drop",
"Gym",
"Elevator",
"Valet Parking"
],
"dodont": [
{
"do_or_dont": "Do",
"what": "Vegetarians"
},
{
"do_or_dont": "Do",
"what": "Family"
},
{
"do_or_dont": "Dont",
"what": "Loud Music"
},
{
"do_or_dont": "Dont",
"what": "Booze"
}
]

这是我写的查询:
"filter": {
"and": {
"filters": [
{
"nested" : {
"path" : "dodont",
"filter" : {
"bool" : {
"must": [{"and" : [
{
"term" : {"dodont.do_or_dont" : "Do"}
},
{
"term" : {"dodont.what" : "Vegetarians"}
}
]},
{"and" : [
{
"term" : {"dodont.do_or_dont" : "Do"}
},
{
"term" : {"dodont.what" : "Family"}
}
]}]
}

}
}
}
]
}
}

现在,此查询返回空结果,但是当我在上面的代码中将bool中的“必须”更改为“应该”时,它将返回以上文档作为结果(只有1个文档与此过滤器匹配,如上所示),理想情况下,“必须”条件应该返回上面的文档,我想为“做”和“不做”传递多个对象,而我只想要与所有对象匹配的结果,但我不能这样做。我应该怎么做?

最佳答案

您需要在嵌套文档上拆分两个条件,因为dodont嵌套数组的每个元素在概念上都是一个单独的文档:

{
"filter": {
"and": {
"filters": [
{
"nested": {
"path": "dodont",
"filter": {
"and": [
{
"term": {
"dodont.do_or_dont": "Do"
}
},
{
"term": {
"dodont.what": "Vegetarians"
}
}
]
}
}
},
{
"nested": {
"path": "dodont",
"filter": {
"and": [
{
"term": {
"dodont.do_or_dont": "Do"
}
},
{
"term": {
"dodont.what": "Family"
}
}
]
}
}
}
]
}
}
}

关于elasticsearch - Elastic Search 1.7.3嵌套过滤器:匹配对象数组中的术语,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34202071/

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