ElasticSearch - search parsed and not_analyzed multi_field in one query

I have an index field 'properties.language' with a value of 'en sv'. This field has a multi-valued display consisting of two fields, one of which is analyzed (name "language"), and the other non-analysis (name "_exact").

How can I create one search query without querying both "properties.language" and "properties.language._exact"?

Edit:

Here is my configuration:

Indexed Data:

{ "_index": "51ded0be98035", "_type": "user", "_id": "WUzwcwhTRbKur7J5ZY_hgA", "_version": 1, "_score": 1, "_source": { "properties": { "language":"en sv" } } } 

Mapping for user type:

 { "user": { "properties": { "properties": { "properties": { "language": { "type": "multi_field", "fields": { "language": { "type": "string", "analyzer": "standard", "index": "analyzed" }, "_exact": { "type": "string", "index": "not_analyzed" } } } } } } } } 

Search query:

 { "query": { "filtered": { "query": { "match_all": {} }, "filter": { "bool": { "must": [{ "or": [{ "term": { "properties.language": "en sv" } }, { "term": { "properties.language._exact": "en sv" } }] }] } } } } } 
+2
elasticsearch
source share
1 answer

Consider indexing the language field using multivalued fields (i.e. arrays) instead of Elasticearch: http://www.elasticsearch.org/guide/reference/mapping/array-type/ . As you do now, set index to not_analyzed .

When indexing your data instead of a single value of 'en sv' , go instead of ['en', 'sv'] , and ES will take care of the rest.

For queries, this gives you the opportunity to do the following to find elements with both en and sv :

 { "query": { "filtered": { "query": { "match_all": {} }, "filter": { "bool": { "must": [{ "term": { "properties.language": "en" } }, { "term": { "properties.language": "sv" } }] } } } } } 

Or even better, find more brevity / flexibility by using terms query / filter instead of term : http://www.elasticsearch.org/guide/reference/query-dsl/terms-query/

+3
source share

All Articles