php - AND OR query in elastic search -


i need dynamically make elastic search query based on and, or query.

user inputs string similar sql format:

((("query1 query2" or query3) or query4) , (query5 or query6)) , query7 

i parse array:

[     'and' => [         [             'and' => [                 [                     'or' => [                         [                             'or' => [                                 '" query1 query 2"',                                 'query3'                             ]                         ],                         'query4'                     ]                 ],                 [                     'or' => [                         'query5',                         'query6'                     ]                 ]             ]          ],         'query7'     ]  ] 

and based on array need make search 1 field.

something like:

{"bool":{"must":[{"match":{"title":"research"}},{"match":{"title":"lecturer"}}]}} 

but i'm stuck nested conditions. please advise.

you can use nested bool nested conditions.

((("query1 query 2" or query3) or query4) , (query5 or query6)) , query7 

can expressed as:

{     "query" : {         "bool":{             "must" : [                 {                                "bool":{    // ((("query1 query 2" or query3) or query4) , (query5 or query6))                          "must" : [                               {                                 "bool":{    // (("query1 query 2" or query3) or query4)                                     "should" : [                                                                             {                                             "bool":{    // ("query1 query 2" or query3)                                                 "should" : [                                                     {"match": // query1 query2},                                                     {"match": // query3}                                                 ]                                             }                                         },                                         {"match": // query4}                                     ]                                 }                             },                             {                                 "bool":{    // (query5 or query6)                                     "should" : [                                         {"match": // query5},                                         {"match": // query6}                                     ]                                 }                             }                         ]                     }                 },                 {match":    //...  query7}             ]         }        } } 

Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -