# Query match

**URL:** <https://discuss.elastic.co/t/query-match/19865>\
**Category:** Elasticsearch\
**Created:** [September 18, 2014, 11:43am UTC](https://discuss.elastic.co/t/query-match/19865 "2014-09-18T11:43:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dk\_2](https://avatars.discourse-cdn.com/v4/letter/d/b5a626/32.png) [@dk\_2](https://discuss.elastic.co/u/dk_2)\
**Post date:** [September 18, 2014, 11:43am UTC](https://discuss.elastic.co/t/query-match/19865/1 "2014-09-18T11:43:10Z")

</div>

I am trying to match a query against the value in the "test" field

Following are the documents indexed -

curl -XPUT '[http://localhost:9200/twitter/tweet/1](http://localhost:9200/twitter/tweet/1)' -d '{  
"test" : "routers switches"  
}'

curl -XPUT '[http://localhost:9200/twitter/tweet/2](http://localhost:9200/twitter/tweet/2)' -d '{  
"test" : "routers"  
}'

curl -XPUT '[http://localhost:9200/twitter/tweet/3](http://localhost:9200/twitter/tweet/3)' -d '{  
"test" : "switches hubs"  
}'

\*User's query - \*

curl -XGET [http://localhost:9200/twitter/tweet/\_search](http://localhost:9200/twitter/tweet/_search) -d '{  
"query":  
{  
"match" : {  
"test" : {  
"query" : "routers and switches for home"  
}  
}  
}  
}'

_Desired Output -_  
document 1 : routers switches  
document 2 : routers

I do not want the third document "switches hubs" in the results since it  
has hubs which is not part of the user query.

Can somebody help me in a writing a query for this requirement?

Thanks  
-dk

--  
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/986a3db5-5645-4527-b647-d797a88fcd4c%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/986a3db5-5645-4527-b647-d797a88fcd4c%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Ramy](https://avatars.discourse-cdn.com/v4/letter/r/8491ac/32.png) [@Ramy](https://discuss.elastic.co/u/Ramy)\
**Post date:** [September 18, 2014, 1:52pm UTC](https://discuss.elastic.co/t/query-match/19865/2 "2014-09-18T13:52:21Z")

</div>

Have you tried like this?

"query": {  
"match": {  
"test": {  
"query": "routers and switches for home",  
_"operator": "and"_  
}  
}  
}

--  
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/bd96b698-5c71-4297-8a23-dc775416a862%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/bd96b698-5c71-4297-8a23-dc775416a862%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![dk\_2](https://avatars.discourse-cdn.com/v4/letter/d/b5a626/32.png) [@dk\_2](https://discuss.elastic.co/u/dk_2)\
**Post date:** [September 18, 2014, 2:43pm UTC](https://discuss.elastic.co/t/query-match/19865/3 "2014-09-18T14:43:18Z")

</div>

Yes, but that wouldn't serve the purpose I was looking for. Using "ÄND"  
operator, wouldn't give me any results at all since there are no documents  
which has all the words in the User Query.

On Thursday, September 18, 2014 7:22:22 PM UTC+5:30, Ramy wrote:

> Have you tried like this?
> 
> "query": {  
> "match": {  
> "test": {  
> "query": "routers and switches for home",  
> _"operator": "and"_  
> }  
> }  
> }

--  
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/8b9fe175-494f-4b5c-9b97-e580c879c4c3%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/8b9fe175-494f-4b5c-9b97-e580c879c4c3%40googlegroups.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:01am UTC](https://discuss.elastic.co/t/query-match/19865/4 "2017-07-06T01:01:14Z")

</div>


