Thanigaivelan
Thanigaivelan

Reputation: 175

Multiple Field search in Elasticsearch

How can we do multiple field search in Elastic search.

for example I want to search subcategory and region, for one field it is working for multiple field search how we have to do.

Below link is working fine, since I am using one field only for search

http://34c512ba34534fffdfd12abfd69f2458.us-east-1.aws.found.io:9200/episodes/episode/_search?q=sub_cat_seo_url:english-news&sort=pubdate_timestamp:desc

but when I try to search multiple field for example sub_cat_seo_url and region it is not working

see this link (not working)

http://34c512ba34534fffdfd12abfd69f2458.us-east-1.aws.found.io:9200/episodes/episode/_search?q=sub_cat_seo_url:english-news,region:1&sort=pubdate_timestamp:desc

http://34c512ba34534fffdfd12abfd69f2458.us-east-1.aws.found.io:9200/episodes/episode/_search?q=sub_cat_seo_url:english-news&region:1&sort=pubdate_timestamp:desc

Upvotes: 0

Views: 95

Answers (1)

Rahul
Rahul

Reputation: 16355

According to documentation, it should work

See http://www.elasticsearch.org/guide/reference/query-dsl/query-string-query.html

That being said, you can also use the following:

http://34c512ba34534fffdfd12abfd69f2458.us-east-1.aws.found.io:9200/episodes/episode/_search?q=%2Bsub_cat_seo_url%3Aenglish-news+%2Bregion%3A1&sort=pubdate_timestamp:desc

NOTE : The existing mapping makes your field "sub_cat_seo_url" analyzed which is analyzed using standard analyzer. Hence, when you are searching for "english-news" it gets tokenized into "english", "news" which results in any document matching either english or news to be valid matches. For eg. "telugu-news" is a valid match for your query. Not sure if it is intentional.

In your mapping you need to mark it as "not_analyzed" for exact match.

Note : %2b is decoded as '+' whereas '+' is decoded as ' '

Upvotes: 0

Related Questions