# Can elasticsearch query some words and the words has some relationship

**URL:** <https://discuss.elastic.co/t/can-elasticsearch-query-some-words-and-the-words-has-some-relationship/15964>\
**Category:** Elasticsearch\
**Created:** [February 22, 2014, 9:05am UTC](https://discuss.elastic.co/t/can-elasticsearch-query-some-words-and-the-words-has-some-relationship/15964 "2014-02-22T09:05:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![xjj210130](https://avatars.discourse-cdn.com/v4/letter/x/c5a1d2/32.png) [@xjj210130](https://discuss.elastic.co/u/xjj210130)\
**Post date:** [February 22, 2014, 9:05am UTC](https://discuss.elastic.co/t/can-elasticsearch-query-some-words-and-the-words-has-some-relationship/15964/1 "2014-02-22T09:05:52Z")

</div>

Hi all:

If the data format is following, can elasticsearch query it correctly?

The first data like this:  
A:  
{

"attrspec\_id":[{"attr\_id":55,"attr\_value":"barnd","optiona":[{"option\_id":5710,"option\_value":"Dell"},{"attr\_id":39715,"attr\_value":"type","option\_id":0,"option\_value":"8135"}]  
}

The second data like this:  
B

{

"attrspec\_id":[{"attr\_id":55,"attr\_value":"barnd","option":[{"option\_id":571,"option\_value":"CX"},{"attr\_id":39715,"attr\_value":"type","option\_id":0,"option\_value":"8135"},.{"attr\_id":48,"attr\_value":"barnd","option":[{"option\_id":5710,"option\_value":"CPU  
4X"},{"attr\_id":39715,"attr\_value":"type","option\_id":0,"option\_value":"8135"}]  
}

if i uses the following query

{

"query\_string" : {"default\_operator":"and", "query":" attr\_id:55 and  
option.option\_id:5710 "}}}

}

Both A and B is selected. In fact i want to select A.  
Thanks very much

--  
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/229523e1-1e94-46cc-be73-0ead541dbdab%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/229523e1-1e94-46cc-be73-0ead541dbdab%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [February 22, 2014, 9:10am UTC](https://discuss.elastic.co/t/can-elasticsearch-query-some-words-and-the-words-has-some-relationship/15964/2 "2014-02-22T09:10:15Z")

</div>

You need to change your mapping and use nested docs.

--  
David 😉  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 22 févr. 2014 à 10:05, [xjj210130@gmail.com](mailto:xjj210130@gmail.com) a écrit :

> Hi all:
> 
> If the data format is following, can elasticsearch query it correctly?
> 
> The first data like this:  
> A:  
> {
> 
> "attrspec\_id":[{"attr\_id":55,"attr\_value":"barnd","optiona":[{"option\_id":5710,"option\_value":"Dell"},{"attr\_id":39715,"attr\_value":"type","option\_id":0,"option\_value":"8135"}]  
> }
> 
> The second data like this:  
> B
> 
> {
> 
> "attrspec\_id":[{"attr\_id":55,"attr\_value":"barnd","option":[{"option\_id":571,"option\_value":"CX"},{"attr\_id":39715,"attr\_value":"type","option\_id":0,"option\_value":"8135"},.{"attr\_id":48,"attr\_value":"barnd","option":[{"option\_id":5710,"option\_value":"CPU 4X"},{"attr\_id":39715,"attr\_value":"type","option\_id":0,"option\_value":"8135"}]  
> }
> 
> if i uses the following query
> 
> {
> 
> "query\_string" : {"default\_operator":"and", "query":" attr\_id:55 and option.option\_id:5710 "}}}
> 
> }
> 
> ## Both A and B is selected. In fact i want to select A. Thanks very much
> 
> 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/229523e1-1e94-46cc-be73-0ead541dbdab%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/229523e1-1e94-46cc-be73-0ead541dbdab%40googlegroups.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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/A5167F95-BA3A-400D-9056-184E60055997%40pilato.fr](https://groups.google.com/d/msgid/elasticsearch/A5167F95-BA3A-400D-9056-184E60055997%40pilato.fr).  
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, 1:48am UTC](https://discuss.elastic.co/t/can-elasticsearch-query-some-words-and-the-words-has-some-relationship/15964/3 "2017-07-06T01:48:07Z")

</div>


