# Prefix query with multiple "prefixes"/words

**URL:** https://discuss.elastic.co/t/prefix-query-with-multiple-prefixes-words/17724
**Category:** Elasticsearch
**Created:** [May 26, 2014, 11:21am UTC](https://discuss.elastic.co/t/prefix-query-with-multiple-prefixes-words/17724 "2014-05-26T11:21:27Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Felix\_Schwarz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/felix_schwarz/32/1530_2.png) [@Felix\_Schwarz](https://discuss.elastic.co/u/Felix_Schwarz)
#### Post date: [May 26, 2014, 11:21am UTC](https://discuss.elastic.co/t/prefix-query-with-multiple-prefixes-words/17724/1 "2014-05-26T11:21:27Z")

</div>

I'm looking for a query so that "foo baz" matches the following documents:  
"foobar baz"  
"foo baz"  
"baz foo"  
"foo bazilion"

Basically I'd like to break down the search string into words and look for a  
(prefix)match of all words in the index.

currently I'm using this query  
'multi\_match': {  
'query': query\_string,  
'fields': ['\_all'],  
'type': 'phrase\_prefix',  
}  
but it only works for a single word. For example a query for "baz foo" (word  
order inverted) does not return a result.  
(I'm also open for pretty expensive queries if that's necessary - there are  
only few searches so functionality wins over raw performance.)

Any suggestions which query type I should use?

Thank you,  
Felix

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/538323B7.8020705%40oss.schwarz.eu](https://groups.google.com/d/msgid/elasticsearch/538323B7.8020705%40oss.schwarz.eu).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![jprante](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jprante/32/44941_2.png) [@jprante](https://discuss.elastic.co/u/jprante)
#### Post date: [May 26, 2014, 1:53pm UTC](https://discuss.elastic.co/t/prefix-query-with-multiple-prefixes-words/17724/2 "2014-05-26T13:53:15Z")

</div>

See [Prefix OR query with Elasticsearch · GitHub](https://gist.github.com/jprante/bdf9a9755a64bc23afbe)

Jörg

On Mon, May 26, 2014 at 1:21 PM, Felix Schwarz \<felix.schwarz@oss.schwarz.eu

> wrote:

> I'm looking for a query so that "foo baz" matches the following documents:  
> "foobar baz"  
> "foo baz"  
> "baz foo"  
> "foo bazilion"
> 
> Basically I'd like to break down the search string into words and look for  
> a  
> (prefix)match of all words in the index.
> 
> currently I'm using this query  
> 'multi\_match': {  
> 'query': query\_string,  
> 'fields': ['\_all'],  
> 'type': 'phrase\_prefix',  
> }  
> but it only works for a single word. For example a query for "baz foo"  
> (word  
> order inverted) does not return a result.  
> (I'm also open for pretty expensive queries if that's necessary - there are  
> only few searches so functionality wins over raw performance.)
> 
> Any suggestions which query type I should use?
> 
> Thank you,  
> Felix
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/538323B7.8020705%40oss.schwarz.eu](https://groups.google.com/d/msgid/elasticsearch/538323B7.8020705%40oss.schwarz.eu)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAKdsXoEnvM84vmri-7WXUR8zXV7YsxRyqAhH%2BWaZQ7n5rqnD%3Dw%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAKdsXoEnvM84vmri-7WXUR8zXV7YsxRyqAhH%2BWaZQ7n5rqnD%3Dw%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [July 6, 2017, 1:26am UTC](https://discuss.elastic.co/t/prefix-query-with-multiple-prefixes-words/17724/3 "2017-07-06T01:26:55Z")

</div>


