# Multi-field, multi-word, match without query\_string

**URL:** <https://discuss.elastic.co/t/multi-field-multi-word-match-without-query-string/11164>\
**Category:** Elasticsearch\
**Created:** [March 15, 2013, 1:11am UTC](https://discuss.elastic.co/t/multi-field-multi-word-match-without-query-string/11164 "2013-03-15T01:11:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bruno\_Miranda](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bruno_miranda/32/746_2.png) [@Bruno\_Miranda](https://discuss.elastic.co/u/Bruno_Miranda)\
**Post date:** [March 15, 2013, 1:11am UTC](https://discuss.elastic.co/t/multi-field-multi-word-match-without-query-string/11164/1 "2013-03-15T01:11:26Z")

</div>

I would like to be able to match a multi word search against multiple  
fields where every word searched is contained in _any_ of the fields, any  
combination. The catch is I would like to _avoid using_ query\_string.

curl -X POST "[http://localhost:9200/index/document/1](http://localhost:9200/index/document/1)" -d '{"id":1,"firstname":"john","middlename":"clark","lastname":"smith"}'  
curl -X POST "[http://localhost:9200/index/document/2](http://localhost:9200/index/document/2)" -d '{"id":2,"firstname":"john","middlename":"paladini","lastname":"miranda"}'

I would like the search for 'John Smith' to match only document 1. The  
following query does what I need but I would rather avoid using  
query\_string in case the user passes "OR", "AND" and any of the other  
advanced params.

curl -X GET '[http://localhost:9200/index/\_search?per\_page=10&pretty](http://localhost:9200/index/_search?per_page=10&pretty)' -d '{  
"query": {  
"query\_string": {  
"query": "john smith",  
"default\_operator": "AND",  
"fields": [  
"firstname",  
"lastname",  
"middlename"  
]  
}  
}  
}'

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [March 15, 2013, 11:23am UTC](https://discuss.elastic.co/t/multi-field-multi-word-match-without-query-string/11164/2 "2013-03-15T11:23:49Z")

</div>

On Thu, 2013-03-14 at 18:11 -0700, Bruno Miranda wrote:

> I would like to be able to match a multi word search against multiple  
> fields where every word searched is contained in any of the fields,  
> any combination. The catch is I would like to avoid using  
> query\_string.

Hi Bruno

I've answered your question in detail on StackOverflow:

> <https://stackoverflow.com/questions/15423033/multi-field-multi-word-match-without-query-string/15430238#15430238>

clint

> curl -X POST "[http://localhost:9200/index/document/1](http://localhost:9200/index/document/1)" -d '{"id":1,"firstname":"john","middlename":"clark","lastname":"smith"}'  
> curl -X POST "[http://localhost:9200/index/document/2](http://localhost:9200/index/document/2)" -d '{"id":2,"firstname":"john","middlename":"paladini","lastname":"miranda"}'
> 
> I would like the search for 'John Smith' to match only document 1. The  
> following query does what I need but I would rather avoid using  
> query\_string in case the user passes "OR", "AND" and any of the other  
> advanced params.
> 
> ## curl -X GET '[http://localhost:9200/index/\_search?per\_page=10&pretty](http://localhost:9200/index/_search?per_page=10&pretty)' -d '{ "query": { "query\_string": { "query": "john smith", "default\_operator": "AND", "fields": ["firstname", "lastname", "middlename"] } } }'
> 
> 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).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 2:46am UTC](https://discuss.elastic.co/t/multi-field-multi-word-match-without-query-string/11164/3 "2017-07-06T02:46:18Z")

</div>


