# Question on search on "\_source"

**URL:** <https://discuss.elastic.co/t/question-on-search-on--source/17000>\
**Category:** Elasticsearch\
**Created:** [April 14, 2014, 11:20am UTC](https://discuss.elastic.co/t/question-on-search-on--source/17000 "2014-04-14T11:20:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![S\_Dutta](https://avatars.discourse-cdn.com/v4/letter/s/bb73d2/32.png) [@S\_Dutta](https://discuss.elastic.co/u/S_Dutta)\
**Post date:** [April 14, 2014, 11:20am UTC](https://discuss.elastic.co/t/question-on-search-on--source/17000/1 "2014-04-14T11:20:31Z")

</div>

Hello,

I have a small DB where I am trying to filter out certain items based on  
the value of "ifpresent" tag as shown below. The query should return me the  
list of items (or UUID of the items) for which ifpresent = 1. I have tried  
the Filters and Queries, but no avail.

I tried queries like the following:  
curl -XGET [http://localhost:9200/searchtest/S@yahoo.com/\_search?routing=0](http://localhost:9200/searchtest/S@yahoo.com/_search?routing=0)  
-d { "query":{ "filtered":{ "query":{ "match\_all":{} }, "filter":{  
"searchItems":{ "ifpresent":0 } } } }

but to no available. Any clues on how to get this data?

The DB looks like the following:

Result Source  
{  
\_index: searchtest  
\_type: [S@yahoo.com](mailto:S@yahoo.com)  
\_id: 4dc8cc35-072d-49c2-b34a-6db248ed03d6  
\_version: 2  
\_score: 1  
\_source: {  
tags: [  
userdetails  
]  
searchItems: [  
[

{"itemUUID":"b1deb6db-8afc-40b7-8d0f-abb50ef6fc96","ifpresent":"1"}

{"itemUUID":"ef984bc9-07dd-4ef3-981a-81a633dbf137","ifpresent":"0"}

{"itemUUID":"e7f9c282-18f6-43f1-8531-b694ac4e0c03","ifpresent":"2"}

{"itemUUID":"c681c581-32f2-46f7-907d-3a19c466bc9c","ifpresent":"0"}

{"itemUUID":"283bc3e9-55ce-4250-a88e-e18286e5dc8d","ifpresent":"3"}

{"itemUUID":"6889defb-262c-4abd-bb21-f0e233a88379","ifpresent":"0"}

{"itemUUID":"1b84dfeb-e80d-4e8b-bf6d-41de0dc99a8e","ifpresent":"4"}

{"itemUUID":"4d959b71-ab17-43fe-9606-47121984fc86","ifpresent":"0"}

{"itemUUID":"e5f99931-a305-4e13-8e8f-9b7c8d0b99e2","ifpresent":"5"}

{"itemUUID":"09da7e17-9513-4c9b-b437-ca94c26b7389","ifpresent":"0"}  
]  
]  
lastSyncTimeL: 0  
appversion: 1.0  
lName: Dutta  
fName: S  
id: userdetails  
lastSyncTimeS:  
deviceOSVersion: 6.0  
deviceType: Android  
gender: M  
pictureurl: [yahoo.com](http://yahoo.com)  
mi: ""  
createDt: 2014-04-14T05:19:31.953Z  
referredNewUsers: [  
null  
]  
}

}

--  
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/68b47ab8-a43f-4e8c-9c16-a88d037edcce%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/68b47ab8-a43f-4e8c-9c16-a88d037edcce%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Binh\_Ly\_2](https://avatars.discourse-cdn.com/v4/letter/b/d07c76/32.png) [@Binh\_Ly\_2](https://discuss.elastic.co/u/Binh_Ly_2)\
**Post date:** [April 16, 2014, 1:37pm UTC](https://discuss.elastic.co/t/question-on-search-on--source/17000/2 "2014-04-16T13:37:38Z")

</div>

1. You likely want a term filter:

{  
"query": {  
"filtered": {  
"filter": {  
"term": {  
"searchItems.ifpresent": 1  
}  
}  
}  
}  
}

1. If your document is structured like above, you cannot extract only a  
partial (searchItems element) that matches your criteria. The search will  
return your document in its entirety. You could filter out parts of the  
document being returned (but not by your search criteria)

--  
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/938bc11b-48a8-45d4-ad75-dfc036028ea2%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/938bc11b-48a8-45d4-ad75-dfc036028ea2%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [April 21, 2014, 12:29pm UTC](https://discuss.elastic.co/t/question-on-search-on--source/17000/3 "2014-04-21T12:29:35Z")

</div>

Hey,

elasticsearch operates on a per-document base. So if only one of the  
documents in the searchitems array is ifpresent=0, the whole document is  
being returned. If you want different behaviour, you could take a look at  
parent/child or nested documents or rethink your indexing strategy,  
depending on the requirements.

--Alex

On Mon, Apr 14, 2014 at 1:20 PM, S Dutta [subhayan.dutta@gmail.com](mailto:subhayan.dutta@gmail.com) wrote:

> Hello,
> 
> I have a small DB where I am trying to filter out certain items based on  
> the value of "ifpresent" tag as shown below. The query should return me  
> the list of items (or UUID of the items) for which ifpresent = 1. I have  
> tried the Filters and Queries, but no avail.
> 
> I tried queries like the following:  
> curl -XGET [http://localhost:9200/searchtest/S@yahoo.com/\_search?routing=0-d](http://localhost:9200/searchtest/S@yahoo.com/_search?routing=0-d) { "query":{ "filtered":{ "query":{ "match\_all":{} }, "filter":{  
> "searchItems":{ "ifpresent":0 } } } }
> 
> but to no available. Any clues on how to get this data?
> 
> The DB looks like the following:
> 
> Result Source  
> {  
> \_index: searchtest  
> \_type: [S@yahoo.com](mailto:S@yahoo.com)  
> \_id: 4dc8cc35-072d-49c2-b34a-6db248ed03d6  
> \_version: 2  
> \_score: 1  
> \_source: {  
> tags: [  
> userdetails  
> ]  
> searchItems: [  
> [
> 
> {"itemUUID":"b1deb6db-8afc-40b7-8d0f-abb50ef6fc96","ifpresent":"1"}
> 
> {"itemUUID":"ef984bc9-07dd-4ef3-981a-81a633dbf137","ifpresent":"0"}
> 
> {"itemUUID":"e7f9c282-18f6-43f1-8531-b694ac4e0c03","ifpresent":"2"}
> 
> {"itemUUID":"c681c581-32f2-46f7-907d-3a19c466bc9c","ifpresent":"0"}
> 
> {"itemUUID":"283bc3e9-55ce-4250-a88e-e18286e5dc8d","ifpresent":"3"}
> 
> {"itemUUID":"6889defb-262c-4abd-bb21-f0e233a88379","ifpresent":"0"}
> 
> {"itemUUID":"1b84dfeb-e80d-4e8b-bf6d-41de0dc99a8e","ifpresent":"4"}
> 
> {"itemUUID":"4d959b71-ab17-43fe-9606-47121984fc86","ifpresent":"0"}
> 
> {"itemUUID":"e5f99931-a305-4e13-8e8f-9b7c8d0b99e2","ifpresent":"5"}
> 
> {"itemUUID":"09da7e17-9513-4c9b-b437-ca94c26b7389","ifpresent":"0"}  
> ]  
> ]  
> lastSyncTimeL: 0  
> appversion: 1.0  
> lName: Dutta  
> fName: S  
> id: userdetails  
> lastSyncTimeS:  
> deviceOSVersion: 6.0  
> deviceType: Android  
> gender: M  
> pictureurl: [yahoo.com](http://yahoo.com)  
> mi: ""  
> createDt: 2014-04-14T05:19:31.953Z  
> referredNewUsers: [  
> null  
> ]  
> }
> 
> }
> 
> --  
> 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/68b47ab8-a43f-4e8c-9c16-a88d037edcce%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/68b47ab8-a43f-4e8c-9c16-a88d037edcce%40googlegroups.com)[https://groups.google.com/d/msgid/elasticsearch/68b47ab8-a43f-4e8c-9c16-a88d037edcce%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/68b47ab8-a43f-4e8c-9c16-a88d037edcce%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> 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/CAGCwEM9%3DHGgadHaHnkVk%3DvgMYiNCmjYUPXvFZ\_HnSWS5%3DJ1dbA%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGCwEM9%3DHGgadHaHnkVk%3DvgMYiNCmjYUPXvFZ_HnSWS5%3DJ1dbA%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:34am UTC](https://discuss.elastic.co/t/question-on-search-on--source/17000/4 "2017-07-06T01:34:35Z")

</div>

Closed on July 6, 2017, 1:34am UTC


