gpt4 book ai didi

elasticsearch - Elasticsearch(2.4)must_not过滤器和数组

转载 作者:行者123 更新时间:2023-12-02 22:59:07 25 4
gpt4 key购买 nike

我的文档中具有以下数组结构:

"usages": [
{
"type": 1,
"area": 207
},
{
"type": 6,
"area": 629
},
...
]

如果数组中只有一个匹配项,如何编写不返回文档的查询?

该查询将返回文档,因为在“type”上存在匹配项:6
"query": {
"bool": {
"must_not": [
{
"term": {
"usages.type": 1
}
}
]
}
}

以及如果有2个参数,例如:usage.type不应为1和3,如何查询。

最佳答案

您是否尝试将数组描述为嵌套字段?

https://www.elastic.co/guide/en/elasticsearch/reference/2.3/nested.html

那可以解决您的问题。
请参阅以下示例:

PUT /my_index 
{
}


PUT /my_index/_mapping/user
{
"properties":
{
"usage":
{
"type": "nested"
}
}
}


PUT /my_index/user/1
{
"usages":
[
{
"type": 1,
"area": 207
},
{
"type": 6,
"area": 629
}
]
}


GET /my_index/_search
{
"query": {
"bool": {
"must_not": [
{
"term": {
"usages.type": 1
}
}
]
}
}
}

关于elasticsearch - Elasticsearch(2.4)must_not过滤器和数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41058143/

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