query_string 嵌套过滤器中的过滤器抛出错误

query_string filter inside a nested filter throws an error

在此示例中,我放置了一个完整的查询示例,该示例已配对到让我卡住的非工作部分。

基本上,我们有一个文档在 datailItems 下有一个嵌套文档类型,并且尝试对该嵌套文档中的字段执行 query_string 过滤器失败。我将相同的部分 运行 用于非嵌套字段并且它有效。所以很明显我做错了什么。

我收到的错误是nested: QueryParsingException[[******] [_na] filter malformed, must start with start_object]

那么,正确的做法是什么?

一些注意事项。 "and"s 用于包含布尔值、范围等的进一步过滤要求......我已经为这个例子去掉了那些额外的要求。

{
    "size" : 1,
    "query" : {
        "filtered" : {
            "filter" : {
                "and" : [{
                        "nested" : {
                            "path" : "detailItems",
                            "filter" : {
                                "and" : [{
                                        "query" : {
                                            "query_string" : {
                                                "detailItems.name" : {
                                                    "query" : "mastersettings",
                                                    "minimum_should_match" : 1
                                                }
                                            }
                                        }
                                    }
                                ]
                            }
                        }
                    }
                ]
            }
        }
    }
}

OP 中的 query_string 在语法上不正确,以下是如何重写查询字符串的示例:

  "size" : 1,
    "query" : {
        "filtered" : {
            "filter" : {
                "and" : [{
                        "nested" : {
                            "path" : "detailItems",
                            "filter" : {
                                "and" : [{
                                        "query" : {
                                            "query_string" : {
                                                "fields": [
                                                   "detailItems.name" 
                                                ], 
                                                "query" : "mastersettings",
                                                "minimum_should_match" : 1

                                            }
                                        }
                                    }
                                ]
                            }
                        }
                    }
                ]
            }
        }
    }