2016-04-03 13 views
6

Voglio creare l'equivalente del seguente query -Come combinare più query bool in elasticsearch

(city = 'New York' AND state = 'NY') AND ((businessName='Java' and businessName='Shop') OR (category='Java' and category = 'Shop')) 

ho provato diverse combinazioni di query bool mosto e dovrebbe, ma nulla sembra funzionare. Può essere fatto?

+0

ciò che non funziona - si può elaborare? – Sanj

+0

Non riesco a trovare la sintassi corretta. Ottieni sempre qualche eccezione di parsing. – user1935449

risposta

7

Che ne dite di qualcosa di simile:

{ 
    "query": { 
     "match_all": {} 
    }, 
    "filter": { 
     "bool": { 
      "must": [ 
       { 
        "term": { 
         "city": "New york" 
        } 
       }, 
       { 
        "term": { 
         "state": "NY" 
        } 
       }, 
       { 
        "bool": { 
         "should": [ 
          { 
           "bool": { 
            "must": [ 
             { 
              "term": { 
               "businessName": "Java" 
              } 
             }, 
             { 
              "term": { 
               "businessName": "Shop" 
              } 
             } 
            ] 
           } 
          }, 
          { 
           "bool": { 
            "must": [ 
             { 
              "term": { 
               "category": "Java" 
              } 
             }, 
             { 
              "term": { 
               "category": "Shop" 
              } 
             } 
            ] 
           } 
          } 
         ] 
        } 
       } 
      ] 
     } 
    } 
} 
Problemi correlati