Question on search on "_source"


(S Dutta) #1

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 { "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
_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
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/68b47ab8-a43f-4e8c-9c16-a88d037edcce%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


(Binh Ly-2) #2
  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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/938bc11b-48a8-45d4-ad75-dfc036028ea2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


(Alexander Reelsen) #3

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 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 { "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
_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
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.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/68b47ab8-a43f-4e8c-9c16-a88d037edcce%40googlegroups.comhttps://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.

--
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.
To view this discussion on the web visit 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.


(system) #4