Reputation: 23
I have index in elastic search with documents which contains two fields: 'artist' and 'track'. How i can manage search for queries like that 'deep purple smoke', where 'deep purple' will be an artist field and 'smoke' is a beginning of track field? I am trying to do this like that:
self.es.search(MultiMatchQuery(fields=['artist', 'name'], text='deep purple smoke', type='phrase_prefix'), 'mus', 'tracks')
But, I think, ES trying to find full text 'deep purple smoke' in artist and name fields, rather than search each word in artist and name fields, and return document which will contains most highly result.
Upvotes: 1
Views: 448
Reputation: 33351
You are correct, it's searching as a phrase because you set the type to 'phrase_prefix'
. Use a different type, instead. I believe 'most_fields'
would be the best choice, although 'best_fields'
or 'cross_fields'
may also be a reasonable choices.
Per the multi_match documentation:
most_fields
- Finds documents which match any field and combines the _score from each field.cross_fields
- Treats fields with the same analyzer as though they were one big field. Looks for each word in any field.best_fields
- Finds documents which match any field, but uses the _score from the best field.Upvotes: 1