Tuesday, January 2, 2018

Condition in Elastic search query not working

Leave a Comment

I want to search for: When a customer id exists in venue >> blocked_for_customers Then I just want to remove tickets of ticket_type=2 from the search result. The ES query I posted is not working as expected. Can anyone help me to find out what am I doing wrong?

Here is my ES document:

{   "took":44,   "timed_out":false,   "_shards":   {     "total":1,     "successful":1,     "failed":0   },   "hits":   {     "total":1,     "max_score":1,     "hits":     [{       "_index":"es_db",       "_type":"event",       "_id":"123",       "_score":1,       "_source":       {         "event_id":123,         "name":"test event",         "event_date":"2016-08-10T03:30:00",         "status":1,         "venue":         [{           "city":"dummy city",           "name":"dummy name",           "state":"dummy state",           "venue_id":100,           "blocked_for_customers":[1,2]         }],         "ticket_group":         [{           "ticket_type":1,           "available":42,           "price":100,           "customer_id":1,           "id":1         },         {           "ticket_type":3,           "available":5,           "price":12.5,           "id":2,           "customer_id":1         },         {           "ticket_type":2,           "available":10,           "id":3,           "customer_id":1,           "price":10         }]       }     }]   } } 

Here is my ES query :

{   "query":   {     "bool":     {       "must":       [{         "nested":         {           "path":"ticket_group",           "score_mode":"max",           "inner_hits":           {             "from":0,             "size":10000           },           "query":           {             "bool":             {               "must":               [{                 "bool":                 {                   "minimum_should_match":1,                   "should":                   [{                     "bool":                     {                       "must":                       [{                         "match":                         {                           "venue.blocked_for_customers":1                         }                       },                       {                         "terms":                         {                           "ticket_group.ticket_type":[1,3]                         }                       }]                     }                   },                   {                     "bool":                     {                       "must":                       [{                         "bool":                         {                           "must_not":                           [{                             "match":                             {                               "venue.blocked_for_customers":1                             }                           }]                         }                       },                       {                         "bool":                         {                           "must":                           [{                             "terms":                             {                               "ticket_group.ticket_type":[1,3,2]                             }                           }]                         }                       }]                     }                   }]                 }               }]             }           }         }       },       {         "match":         {           "status":1         }       }]     }    },   "size":10,   "from":0,   "sort":   {     "event_date":     {       "order":"asc"     }   } } 

Mappings :

{"mappings": {       "event":{          "properties":{             "event_date":{                "type":"date",                "format":"strict_date_optional_time||epoch_millis"             },             "event_id":{                "type":"integer",                "index":"not_analyzed"             },             "name":{                "type":"string",                "analyzer":"autocomplete",                "search_analyzer":"standard",                "fields":{                   "raw":{                      "type":"string",                      "index":"not_analyzed"                   }                }             },             "status":{                "type":"integer"             },             "ticket_group":{                "type":"nested",                "properties":{                   "price":{                      "type":"double",                      "index":"not_analyzed"                   },                   "ticket_type":{                      "type":"integer"                   },                   "available":{                      "type":"integer"                   },                   "customer_id":{                      "type":"string"                   },                   "id":{                      "type":"integer",                      "index":"not_analyzed"                   }                }             },             "venue":{                "type":"nested",                "properties":{                   "blocked_for_customers" :{                      "type":"string"                   },                   "name":{                      "type":"string",                      "analyzer":"autocomplete",                      "search_analyzer":"standard"                   },                   "venue_id":{                      "type":"string",                      "index":"not_analyzed"                   },                   "city":{                      "type":"string"                   },                   "state":{                      "type":"string"                   }                }             }          }       }    } } 

0 Answers

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment