How to query array of keywords in elastic search filter with space?

I have a list of cities like this:

["New York","Bayern Munchen","Porto Alegre"]

I want to search some query in must or should section and use this cities keywords in filter section, but this cities have white space and elastic search does not response.

{  
   "query":{  
      "bool":{  
         "should":[  
            {  
               "match_phrase":{  
                  "title":"pizza"
               }
            },
            {  
               "match_phrase":{  
                  "content":"foods"
               }
            }
         ],
         "filter":[  
            {  
               "range":{  
                  "date":{  
                     "gte":"2015-01-01"
                  }
               }
            },
            {  
               "terms":{  
                  "cities":[  
                     "New York",
                     "Bayern Munchen",
                     "Porto Alegre"
                  ]
               }
            }
         ],
         "minimum_should_match":1
      }
   }
}

this code use "terms" in filter, but the result is empty. How can i use this keywords in filter section?

I believe you should use "cities.keyword".

{  
               "terms":{  
                  "cities.keyword":[  
                     "New York",
                     "Bayern Munchen",
                     "Porto Alegre"
                  ]
               }
            }
1 Like

thank you very much.:grinning::pray:

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.