gpt4 book ai didi

elasticsearch - 如何在任何嵌套字段中搜索值?

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

基本上,我必须在文档的所有字段中找到匹配的值。
我尝试使用查询字符串,但不幸的是,它仅在第一级字段中搜索。嵌套字段值未使用查询字符串获取,或者可能是我使用的方式错误。
我试过了

GET events/_search
{
"query": {
"bool": {
"must": [
{
"query_string": {
"default_field": "*",
"query": "match"
}
}
]
}
}
}
我将如何查询它检查包括嵌套字段在内的所有字段的方式。
提前致谢

最佳答案

您始终可以有多个子句,一个子句用于一级字段,另一个子句用于在OR条件中组合的嵌套字段:

GET events/_search
{
"query": {
"bool": {
"minimum_should_match": 1,
"should": [
{
"query_string": {
"default_field": "*",
"query": "match",
"lenient": true
}
},
{
"nested": {
"path": "nested_field",
"query": {
"query_string": {
"default_field": "nested_field.*",
"query": "match",
"lenient": true
}
}
}
}
]
}
}
}

关于elasticsearch - 如何在任何嵌套字段中搜索值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63615468/

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