1

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

E.g

{
 "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 ?

alwaysLearn
  • 6,882
  • 7
  • 39
  • 67
  • You may want to clarify what you are trying to do here exactly. Also, what is q? Meanwhile, you may be able to use a script query for this. Another option is to use function score queries where you use filters on the functions. Also, a simple bool query might be good enough here. – Jilles van Gurp Apr 12 '17 at 08:35

1 Answers1

0

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"
                        }
                    }
                }
            }
        }
    }
}
Community
  • 1
  • 1
Vijay
  • 4,694
  • 1
  • 30
  • 38