简体   繁体   中英

Condition based query in elastic search

Is it possible to build query based on the condition in elastic search ?

Eg

{
 "match": {
      "ticket_group.marketplaceticket_source_id": (q.preferredProvider!=0) ? q.preferredProvider:""                                        
 }    
}

In above coe if " q.preferredProvider " is 0 then I want to omit condition for " ticket_group.marketplaceticket_source_id " or you can say that " ticket_group.marketplaceticket_source_id " can take any value otherwise " ticket_group.marketplaceticket_source_id " should match with " q.preferredProvider "

How can I write it in elastic search ?

I think this will will help u :-

Check these link also link link2 link3

{
    "query": {
        "bool": {
            "must_not": {
                "match": {
                    "q.preferredProvider": 0
                }
            },
            "must": {
                "match": {
                    "script": {
                        "script": {
                            "doc['ticket_group.marketplaceticket_source_id'].value ==  doc['q.preferredProvider'].value"
                        }
                    }
                }
            }
        }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM