Help with 'or' filter needed

Days are passing, but still can't get used to the syntax of queries.

My current query structure:

{
    "query":{
        "bool":{
            "must":{  /* --- Here is my full-text search query --- */ 
                "match":{
                    "full_text": {
                    	"query": "test",
                    	"operator": "and",
                    	"fuzziness": "AUTO"
                    }
                }
            },
            "filter":[
                {     /* --- Here are all of my optional faceted search terms goes --- */
                    "term":{
                        "status":"Published"
                    }
                },
                {     /* --- Here are my 2 required 'AND' search terms:` range` and `script`  --- */
                	"range":{
                		"price":{"gt":0}
                	}
                },
                {
                	"script":{
                		"script":{
                			"source":"doc['activated'].value.getMillis() + doc['duration'].value*24*60*60*1000 > System.currentTimeMillis()",
                			"lang":"painless"
                		}
                	}
                }]
        }
    }
}

At this point I'm happy with it.

But there is also a need to have my filter query with my 'AND' search terms (range and script) as 'OR' search terms. And here I'm stuck with syntax.

Any help would be appreciated,
thanks in advance!

Just put another bool query inside filter and put all clauses that should be ORed into should clauses.

Wasn't aware the bool query can be nested inside filter...

Many thanks for the tip!

Now it's much clearer how to construct sophisticated search queries.

My final ORed query looks like this:

{
    "query":{
        "bool":{
            "must":{    /* --- Here is my full-text search query --- */
                "match":{
                    "full_text":{
                        "query":"test",
                        "operator":"and",
                        "fuzziness":"AUTO"
                    }
                }
            },
            "filter":[
                {    /* --- Here are all of my optional faceted search terms --- */
                    "term":{
                        "status":"Published"
                    }
                },
                {
                    "bool":{   /* --- Here are my `OR` search terms  --- */
                        "should":[
                            {
                                "term":{
                                    "price":0
                                }
                            },
                            {
                                "script":{
                                    "script":{
                                        "source":"doc['activated'].value.getMillis() + doc['duration'].value*24*60*60*1000 < System.currentTimeMillis()",
                                        "lang":"painless"
                                    }
                                }
                            }
                        ]
                    }
                }
            ]
        }
    }
}

And it works flawlessly!

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.