Elasticsearch查询错误-[或]查询格式错误,查询名称后没有start_object

时间:2019-03-01 16:28:01

标签: elasticsearch filter

有人可以解释一下此查询有什么问题吗?我需要将此生成的查询从Elasticsearch 2转换为Elasticsearch6。在ES2中,此方法运行良好,但在ES6中,它向我抛出错误: [或]查询格式错误,查询名称后没有start_object 。我迷失了它。或者是必要条件,因为可能存在比此条件更多的条件。

{
    "query": {
        "bool": {
            "filter": {
                "or": [
                    {
                        "nested": {
                            "path": "zalozcovia",
                            "query": {
                                "bool": {
                                    "filter": [
                                        {
                                            "match": {
                                                "zalozcovia.meno": "\u013dubo\u0161"
                                            }
                                        },
                                        {
                                            "match": {
                                                "zalozcovia.priezvisko": "Majgot"
                                            }
                                        },
                                        {
                                            "match": {
                                                "zalozcovia.mesto": "Trnava"
                                            }
                                        }
                                    ]
                                }
                            }
                        }
                    }
                ]
            }
        }
    },
    "size": 20,
    "sort": [
        {
            "rok": "desc"
        },
        {
            "cislo": "desc"
        }
    ]
}

谢谢。

2 个答案:

答案 0 :(得分:2)

在ES6中,没有afaik没有“ OR”查询(https://www.elastic.co/guide/en/elasticsearch/reference/6.4/query-dsl-or-query.html)。您应该使用布尔查询,并在此处使用“应该”部分(https://www.elastic.co/guide/en/elasticsearch/reference/6.4/query-dsl-bool-query.html)。

{
    "query": {
        "bool": {
            "filter": [{
                "bool": {
                    "should": [{
                        "nested": {
                            "path": "zalozcovia",
                            "query": {
                                "bool": {
                                    "filter": [{
                                            "match": {
                                                "zalozcovia.meno": "\u013dubo\u0161"
                                            }
                                        },
                                        {
                                            "match": {
                                                "zalozcovia.priezvisko": "Majgot"
                                            }
                                        },
                                        {
                                            "match": {
                                                "zalozcovia.mesto": "Trnava"
                                            }
                                        }
                                    ]
                                }
                            }
                        }
                    }]
                }
            }]
        }
    },
    "size": 20,
    "sort": [{
            "rok": "desc"
        },
        {
            "cislo": "desc"
        }
    ]
}

答案 1 :(得分:1)

尝试使用应该更改“ filter-or”

{
    "query": {
        "bool": {
              "should" : [
                    {
                        "nested": {
                            "path": "zalozcovia",
                            "query": {
                                "bool": {
                                    "filter": [
                                        {
                                            "match": {
                                                "zalozcovia.meno": "\u013dubo\u0161"
                                            }
                                        },
                                        {
                                            "match": {
                                                "zalozcovia.priezvisko": "Majgot"
                                            }
                                        },
                                        {
                                            "match": {
                                                "zalozcovia.mesto": "Trnava"
                                            }
                                        }
                                    ]
                                }
                            }
                        }
                    }
                ]
            }
    },
    "size": 20,
    "sort": [
        {
            "rok": "desc"
        },
        {
            "cislo": "desc"
        }
    ]
}