Query both root and nested documents

Hello,

Below is the gist related to my question.

I have set up a sample index that contains a couple simple documents that contain a nested type. In addition, I have created a facet that only contains those filtered nested items that relate to the nested filter I have applied. So basically everything is working as I would like, except that in addition to the stores.id filter, I would like to query against the name and/or desc field (i.e. name=samsung), which is at the root level. I have tried a number of different attempts at this, but with no luck. In addition to the gist, I have copied one of the documents below, as well as the query I am using as of now, which is working with just the filter.

curl -X POST "http://localhost:9200/deals_near_me/deals" -d '{
"skuid": "123456",
"name": "Samsung 55 inch TV",
"desc": "Samsung Smart HDTV that really looks nice and is super thin",
"price2" : 300,
"stores":
[
{ "id": "1001", "price": 599, "inv_status" : "avail" },
{ "id": "1002", "price": 699, "inv_status" : "avail" },
{ "id": "1003", "price": 799, "inv_status" : "avail" }
]
}'

curl 'localhost:9200/deals_near_me/deals/_search?pretty=1' -d '{
"query": {
"nested": {
"_scope": "my_scope",
"path": "stores",
"score_mode": "avg",
"query": {
"filtered" : {
"query" : {
"match_all": {}
},
"filter" : {
"term" : { "stores.id" : "1001" }
}
}
}
}
},
"facets" : {
"range1" : {
"range" : {
"stores.price" : [
{ "to" : 200.0 },
{ "from" : 200.0, "to" : 500.0 },
{ "from" : 500.1, "to" : 700.0 },
{ "from" : 700, "to" : 900.0 },
{ "from" : 900, "to" : 1000.0 },
{ "from" : 1000.0 }
]
},
"scope": "my_scope"
}
}
}'

You can place the nested query within a bool query for example, and have
additional queries in this case working "against" the root level doc.

On Wed, Mar 21, 2012 at 10:11 PM, my3sons carey.boldenow@gmail.com wrote:

Hello,

Below is the gist related to my question.

query root and nested documents · GitHub

I have set up a sample index that contains a couple simple documents that
contain a nested type. In addition, I have created a facet that only
contains those filtered nested items that relate to the nested filter I
have
applied. So basically everything is working as I would like, except that in
addition to the stores.id filter, I would like to query against the name
and/or desc field (i.e. name=samsung), which is at the root level. I have
tried a number of different attempts at this, but with no luck. In addition
to the gist, I have copied one of the documents below, as well as the query
I am using as of now, which is working with just the filter.

curl -X POST "http://localhost:9200/deals_near_me/deals" -d '{
"skuid": "123456",
"name": "Samsung 55 inch TV",
"desc": "Samsung Smart HDTV that really looks nice and is super thin",
"price2" : 300,
"stores":
[
{ "id": "1001", "price": 599, "inv_status" : "avail" },
{ "id": "1002", "price": 699, "inv_status" : "avail" },
{ "id": "1003", "price": 799, "inv_status" : "avail" }
]
}'

curl 'localhost:9200/deals_near_me/deals/_search?pretty=1' -d '{
"query": {
"nested": {
"_scope": "my_scope",
"path": "stores",
"score_mode": "avg",
"query": {
"filtered" : {
"query" : {
"match_all": {}
},
"filter" : {
"term" : { "stores.id" : "1001" }
}
}
}
}
},
"facets" : {
"range1" : {
"range" : {
"stores.price" : [
{ "to" : 200.0 },
{ "from" : 200.0, "to" : 500.0 },
{ "from" : 500.1, "to" : 700.0 },
{ "from" : 700, "to" : 900.0 },
{ "from" : 900, "to" : 1000.0 },
{ "from" : 1000.0 }
]
},
"scope": "my_scope"
}
}
}'

--
View this message in context:
http://elasticsearch-users.115913.n3.nabble.com/query-both-root-and-nested-documents-tp3846688p3846688.html
Sent from the Elasticsearch Users mailing list archive at Nabble.com.