2

Can somebody explain me please what is wrong with this query? I need to convert this generated query from Elasticsearch 2 to Elasticsearch 6. In ES2 this one works well, but in ES6 it throws me an error: [or] query malformed, no start_object after query name. I am lost in it. OR is necessary cause there could be more conditions than this one.

{
    "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"
        }
    ]
}

Thanks.

2 Answers 2

3

In ES6 there is afaik no "OR" Query (https://www.elastic.co/guide/en/elasticsearch/reference/6.4/query-dsl-or-query.html). You should use a bool query and use there the "should" Part (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"
        }
    ]
}
Sign up to request clarification or add additional context in comments.

13 Comments

Yes I know but SHOULD throws me the same error only insead of [or] is [should]
Don't add or inside the should part.
I dont. I change the OR to SHOULD.
can you show your corrected query? at least the error somehow shows, that your syntax is still not applicable. i think you should get rid of the first filter and switch or to should.
You removed FILTER level. I missed it. Without filter it works. But I am not sure if I can remove it from the query.
|
2

Try changing "filter-or" with should

{
    "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"
        }
    ]
}

5 Comments

Yes it works but I am not sure if I can remove Filter level from query. Filter should be little efficient cause it does not count a score. Am I right?
I'm not sure sir, But in your query above, seems, it doesn't need filter with or :) You can check this answer for must and filter difference: stackoverflow.com/a/43349478/2057653
I know but there could be more conditions than one.
you can add each condition to should array ? I don't get what is wrong?
Ok I have it. There should be one more BOOL level inside the FILTER. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.