如何在任何嵌套字段中搜索值?
How to search for a value in any nested field?
基本上我必须在文档的所有字段中找到一个匹配值。
我尝试使用查询字符串,但不幸的是,它只在第一级字段中搜索。嵌套字段值不是使用查询字符串获取的,或者可能是我使用它的方式错误。
我试过了
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
}
}
}
}
]
}
}
}
基本上我必须在文档的所有字段中找到一个匹配值。
我尝试使用查询字符串,但不幸的是,它只在第一级字段中搜索。嵌套字段值不是使用查询字符串获取的,或者可能是我使用它的方式错误。
我试过了
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
}
}
}
}
]
}
}
}