Nested Documents - how to search for nested elements, not whole documents

Hi,

I have hierarchical data: orders consist of several order items.

How can I search for a certain orderItem without getting returned the other
items of the same order?
I tried to use nested documents, but I always receive the whole order and
not the requested order item.

Example:

POST /salesorder7
{
"mappings": {
"complete": {
"properties": {
"orderDetails": {
"type": "nested",
"properties": {
"lineItemNumber": {
"type": "string"
},
"productInformation": {
"properties": {
"id": {
"type": "string"
},
"name": {
"type": "string"
}
}
},
"totalLineItemPrice": {
"properties": {
"amount": {
"type": "float"
},
"currency": {
"type": "string"
}
}
},
"orderHeader": {
"properties": {
"orderNumber": {
"type": "string"
}
}
}
}
}
}
}
}
}

PUT /salesorder7/complete/1
{
"orderHeader": {
"orderNumber": "1"
},
"orderDetails": [
{
"lineItemNumber": "11",
"productInformation": {
"name": "product1",
"id": "p1"
},
"totalLineItemPrice": {
"amount": "105.04",
"currency": "EUR"
}
},
{
"totalLineItemPrice": {
"amount": "9.99",
"currency": "EUR"
},
"lineItemNumber": "12",
"productInformation": {
"name": "product2",
"id": "p2"
}
}
]
}

POST /salesorder7/complete/_search
{
"fields": [
"orderHeader.orderNumber",
"orderDetails.unitPrice.amount",
"orderDetails.productInformation.name"
],
"query": {
"nested": {
"path": "orderDetails",
"score_mode": "avg",
"query": {
"bool": {
"must": [
{
"match": {
"orderDetails.productInformation.name":
"product1"
}
}
]
}
}
}
}
}

This returns

{
"took": 7,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 1.4054651,
"hits": [
{
"_index": "salesorder7",
"_type": "complete",
"_id": "1",
"_score": 1.4054651,
"fields": {
"orderDetails.productInformation.name": [
"product1",
"product2"
],
"orderHeader.orderNumber": [
"1"
]
}
}
]
}
}

I want it to return product1 only, and not product1 and product2.

How can I achive this?

Best regards
Henrik

P.S. Sorry for not using CURL, under Windows it seems to only accept single
line nonspaced documents or documents in files.

--
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/4eaf18d4-2db3-4264-8dfc-767ca34d5f28%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

This behavior is currently not possible. The Elasticsearch team is working
on a solution.

--
Ivan
On Oct 28, 2014 5:24 AM, henrik.behrens@shs-viveon.com wrote:

Hi,

I have hierarchical data: orders consist of several order items.

How can I search for a certain orderItem without getting returned the
other items of the same order?
I tried to use nested documents, but I always receive the whole order and
not the requested order item.

Example:

POST /salesorder7
{
"mappings": {
"complete": {
"properties": {
"orderDetails": {
"type": "nested",
"properties": {
"lineItemNumber": {
"type": "string"
},
"productInformation": {
"properties": {
"id": {
"type": "string"
},
"name": {
"type": "string"
}
}
},
"totalLineItemPrice": {
"properties": {
"amount": {
"type": "float"
},
"currency": {
"type": "string"
}
}
},
"orderHeader": {
"properties": {
"orderNumber": {
"type": "string"
}
}
}
}
}
}
}
}
}

PUT /salesorder7/complete/1
{
"orderHeader": {
"orderNumber": "1"
},
"orderDetails": [
{
"lineItemNumber": "11",
"productInformation": {
"name": "product1",
"id": "p1"
},
"totalLineItemPrice": {
"amount": "105.04",
"currency": "EUR"
}
},
{
"totalLineItemPrice": {
"amount": "9.99",
"currency": "EUR"
},
"lineItemNumber": "12",
"productInformation": {
"name": "product2",
"id": "p2"
}
}
]
}

POST /salesorder7/complete/_search
{
"fields": [
"orderHeader.orderNumber",
"orderDetails.unitPrice.amount",
"orderDetails.productInformation.name"
],
"query": {
"nested": {
"path": "orderDetails",
"score_mode": "avg",
"query": {
"bool": {
"must": [
{
"match": {
"orderDetails.productInformation.name":
"product1"
}
}
]
}
}
}
}
}

This returns

{
"took": 7,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 1.4054651,
"hits": [
{
"_index": "salesorder7",
"_type": "complete",
"_id": "1",
"_score": 1.4054651,
"fields": {
"orderDetails.productInformation.name": [
"product1",
"product2"
],
"orderHeader.orderNumber": [
"1"
]
}
}
]
}
}

I want it to return product1 only, and not product1 and product2.

How can I achive this?

Best regards
Henrik

P.S. Sorry for not using CURL, under Windows it seems to only accept
single line nonspaced documents or documents in files.

--
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/4eaf18d4-2db3-4264-8dfc-767ca34d5f28%40googlegroups.com
https://groups.google.com/d/msgid/elasticsearch/4eaf18d4-2db3-4264-8dfc-767ca34d5f28%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/CALY%3DcQCpR3LP%2ByeJDhD9j_kHuwSHQuU79%3DdHR_18-YfAMNsGOw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Is this feature implemented in Elasticsearch 2.3.4 version?? I also have a similar requirement..