Unable to search for parent and child documents using Elasticsearch?

I have indexed a child document in Elasticsearch as follows:

{
_parent: chow-demo
_index: prototype_2013.01.02
_type: chow-clfg
_id: l7jvEgD-SrG-Ws_9ab52IA
_score: 11.600378
_source: {
chow-clfg: {
@type: chow-clfg
clfg: Cg5iUlAvU9IIAAAA8Rg
@timestamp: 2013-01-02T10:15:00.000Z
count: 1
}
}
}

The parent has at least 2 records that has clfg as a common identifier as
follows:

{
_index: "prototype_2013.01.02",
_type: chow-demo,
clfg: Cg5iUlAvU9IIAAAA8Rg,
obid: 97066795
}

However when I query using the "has_child" query, I get no results:

curl -XGET "localhost:9200:/prototype_2013.01.02/chow-demo/_search"
{
"query": {
"has_child": {
"type": "chow-clfg",
"query": {
"term": {
"clfg": "Cg5iUlAvU9IIAAAA8Rg"
}
}
}
}
}

However when I query individually for the documents, there were correct
results returned. Why is that so? Isn't the parent routing supposed to be
able to identify results using the child using the parent field?

--

Hi,

What were the exact index curl commands and did you use a the _parent
mapping? Can you perhaps create a gist, it would be easier
to see what is going wrong.

Martijn

On 2 January 2013 11:41, Jonathan Moo webmusing@gmail.com wrote:

I have indexed a child document in Elasticsearch as follows:

{
_parent: chow-demo
_index: prototype_2013.01.02
_type: chow-clfg
_id: l7jvEgD-SrG-Ws_9ab52IA
_score: 11.600378
_source: {
chow-clfg: {
@type: chow-clfg
clfg: Cg5iUlAvU9IIAAAA8Rg
@timestamp: 2013-01-02T10:15:00.000Z
count: 1
}
}
}

The parent has at least 2 records that has clfg as a common identifier as
follows:

{
_index: "prototype_2013.01.02",
_type: chow-demo,
clfg: Cg5iUlAvU9IIAAAA8Rg,
obid: 97066795
}

However when I query using the "has_child" query, I get no results:

curl -XGET "localhost:9200:/prototype_2013.01.02/chow-demo/_search"
{
"query": {
"has_child": {
"type": "chow-clfg",
"query": {
"term": {
"clfg": "Cg5iUlAvU9IIAAAA8Rg"
}
}
}
}
}

However when I query individually for the documents, there were correct
results returned. Why is that so? Isn't the parent routing supposed to be
able to identify results using the child using the parent field?

--

--
Met vriendelijke groet,

Martijn van Groningen

--

Hi Martijn,

Thanks for helping, I have created the gist
at Unable to search for parent and child documents using Elasticsearch · GitHub.

My curl command structure is as follows:

curl -XPOST "localhost:9200/prototype_2013.01.03/chow-demo/_search" -d
'{
"query": {
"has_child": {
"type": "chow-clfg",
"query": {
"term": {
"clfg": "Cg5iU1BHZ88kAAAAYAE"
}
}
}
}
}'

And I have used the _parent mapping as "chow-demo", but I am unable to get
results.

Jonathan

On Wednesday, 2 January 2013 20:28:54 UTC+8, Martijn v Groningen wrote:

Hi,

What were the exact index curl commands and did you use a the _parent
mapping? Can you perhaps create a gist, it would be easier
to see what is going wrong.

Martijn

On 2 January 2013 11:41, Jonathan Moo <webm...@gmail.com <javascript:>>
wrote:

I have indexed a child document in Elasticsearch as follows:

{
_parent: chow-demo
_index: prototype_2013.01.02
_type: chow-clfg
_id: l7jvEgD-SrG-Ws_9ab52IA
_score: 11.600378
_source: {
chow-clfg: {
@type: chow-clfg
clfg: Cg5iUlAvU9IIAAAA8Rg
@timestamp: 2013-01-02T10:15:00.000Z
count: 1
}
}
}

The parent has at least 2 records that has clfg as a common identifier
as
follows:

{
_index: "prototype_2013.01.02",
_type: chow-demo,
clfg: Cg5iUlAvU9IIAAAA8Rg,
obid: 97066795
}

However when I query using the "has_child" query, I get no results:

curl -XGET "localhost:9200:/prototype_2013.01.02/chow-demo/_search"
{
"query": {
"has_child": {
"type": "chow-clfg",
"query": {
"term": {
"clfg": "Cg5iUlAvU9IIAAAA8Rg"
}
}
}
}
}

However when I query individually for the documents, there were correct
results returned. Why is that so? Isn't the parent routing supposed to
be
able to identify results using the child using the parent field?

--

--
Met vriendelijke groet,

Martijn van Groningen

--

Hi Jonathan,

I created a gist based on your gist:

I couldn't find your index curl commands in your gist. I added these
to my gist. The search request does return hits in this gist.
I also removed the @type and @timestamp fields. I think you just want
to use the timestamp mapping, right?:

Martijn

On 3 January 2013 04:11, Jonathan Moo webmusing@gmail.com wrote:

Hi Martijn,

Thanks for helping, I have created the gist at
Unable to search for parent and child documents using Elasticsearch · GitHub.

My curl command structure is as follows:

curl -XPOST "localhost:9200/prototype_2013.01.03/chow-demo/_search" -d
'{
"query": {
"has_child": {
"type": "chow-clfg",
"query": {
"term": {
"clfg": "Cg5iU1BHZ88kAAAAYAE"
}
}
}
}
}'

And I have used the _parent mapping as "chow-demo", but I am unable to get
results.

Jonathan

On Wednesday, 2 January 2013 20:28:54 UTC+8, Martijn v Groningen wrote:

Hi,

What were the exact index curl commands and did you use a the _parent
mapping? Can you perhaps create a gist, it would be easier
to see what is going wrong.

Martijn

On 2 January 2013 11:41, Jonathan Moo webm...@gmail.com wrote:

I have indexed a child document in Elasticsearch as follows:

{
_parent: chow-demo
_index: prototype_2013.01.02
_type: chow-clfg
_id: l7jvEgD-SrG-Ws_9ab52IA
_score: 11.600378
_source: {
chow-clfg: {
@type: chow-clfg
clfg: Cg5iUlAvU9IIAAAA8Rg
@timestamp: 2013-01-02T10:15:00.000Z
count: 1
}
}
}

The parent has at least 2 records that has clfg as a common identifier
as
follows:

{
_index: "prototype_2013.01.02",
_type: chow-demo,
clfg: Cg5iUlAvU9IIAAAA8Rg,
obid: 97066795
}

However when I query using the "has_child" query, I get no results:

curl -XGET "localhost:9200:/prototype_2013.01.02/chow-demo/_search"
{
"query": {
"has_child": {
"type": "chow-clfg",
"query": {
"term": {
"clfg": "Cg5iUlAvU9IIAAAA8Rg"
}
}
}
}
}

However when I query individually for the documents, there were correct
results returned. Why is that so? Isn't the parent routing supposed to
be
able to identify results using the child using the parent field?

--

--
Met vriendelijke groet,

Martijn van Groningen

--
Met vriendelijke groet,

Martijn van Groningen

--

Hi Martijn,

I think I have a misunderstanding about parent/child mappings. I thought
when I specified _parent as the chow-demo type, it is able to match exact
fields in the parent document as well as the child documents automatically.
Hence I assumed that the term "clfg" in every parent document in the type
"chow-demo" can be queried against with the child document's "clfg" field.

However the actual "_parent" field maps the child document to the parent's
ID, hence since there is no mapping to a specific ID but instead it is
mapped to a parent's type, i get no results.

I probably need to restructure my architecture a bit to fit the
parent/child mapping in Elasticsearch. Thanks so much for your help!

Regards,
Jonathan

On Thursday, 3 January 2013 17:16:27 UTC+8, Martijn v Groningen wrote:

Hi Jonathan,

I created a gist based on your gist:
test.sh · GitHub

I couldn't find your index curl commands in your gist. I added these
to my gist. The search request does return hits in this gist.
I also removed the @type and @timestamp fields. I think you just want
to use the timestamp mapping, right?:
Elasticsearch Platform — Find real-time answers at scale | Elastic

Martijn

On 3 January 2013 04:11, Jonathan Moo <webm...@gmail.com <javascript:>>
wrote:

Hi Martijn,

Thanks for helping, I have created the gist at
Unable to search for parent and child documents using Elasticsearch · GitHub.

My curl command structure is as follows:

curl -XPOST "localhost:9200/prototype_2013.01.03/chow-demo/_search" -d
'{
"query": {
"has_child": {
"type": "chow-clfg",
"query": {
"term": {
"clfg": "Cg5iU1BHZ88kAAAAYAE"
}
}
}
}
}'

And I have used the _parent mapping as "chow-demo", but I am unable to
get
results.

Jonathan

On Wednesday, 2 January 2013 20:28:54 UTC+8, Martijn v Groningen wrote:

Hi,

What were the exact index curl commands and did you use a the _parent
mapping? Can you perhaps create a gist, it would be easier
to see what is going wrong.

Martijn

On 2 January 2013 11:41, Jonathan Moo webm...@gmail.com wrote:

I have indexed a child document in Elasticsearch as follows:

{
_parent: chow-demo
_index: prototype_2013.01.02
_type: chow-clfg
_id: l7jvEgD-SrG-Ws_9ab52IA
_score: 11.600378
_source: {
chow-clfg: {
@type: chow-clfg
clfg: Cg5iUlAvU9IIAAAA8Rg
@timestamp: 2013-01-02T10:15:00.000Z
count: 1
}
}
}

The parent has at least 2 records that has clfg as a common
identifier
as
follows:

{
_index: "prototype_2013.01.02",
_type: chow-demo,
clfg: Cg5iUlAvU9IIAAAA8Rg,
obid: 97066795
}

However when I query using the "has_child" query, I get no results:

curl -XGET "localhost:9200:/prototype_2013.01.02/chow-demo/_search"
{
"query": {
"has_child": {
"type": "chow-clfg",
"query": {
"term": {
"clfg": "Cg5iUlAvU9IIAAAA8Rg"
}
}
}
}
}

However when I query individually for the documents, there were
correct
results returned. Why is that so? Isn't the parent routing supposed
to
be
able to identify results using the child using the parent field?

--

--
Met vriendelijke groet,

Martijn van Groningen

--
Met vriendelijke groet,

Martijn van Groningen

--