Trouble with grand-parent/parent/child relationship


(Chris Burrell) #1

Hi

I'm trying to do something, which I thought was pretty simple. A User can have multiple accounts and an account have multiple messages. For some reason, I can see the parents for accounts but I can't see a parent for the message.

Here are the curl messages that I'm running. Is there something I'm doing that's obviously wrong?

curl -XDELETE 'localhost:9200/myindex'
curl -v -XPUT 'localhost:9200/myindex' -H 'Content-Type: application/json' -d'
{
"mappings": {
"user": {},
"account": {
"_parent": {
"type": "user"
}
},
"message": {
"_parent": {
"type": "account"
}
}

}
}'

curl -XPUT 'localhost:9200/myindex/user/1?pretty&refresh' -H 'Content-Type: application/json' -d'
{
name: "Chris Burrell"
}
'

curl -XPUT 'localhost:9200/myindex/account/2?pretty&parent=1&refresh' -H 'Content-Type: application/json' -d'
{
"accountType": "classic",
"paymentReference": "C1",
"userId": "chris"
}
'

curl -XPUT 'localhost:9200/myindex/account/3?pretty&parent=1&refresh' -H 'Content-Type: application/json' -d'
{
"accountType": "isa",
"paymentReference": "I1",
"userId": "chris"
}
'

curl -XPUT 'localhost:9200/myindex/message/4?pretty&parent=2&refresh' -H 'Content-Type: application/json' -d'
{
"id" : "chrispir1",
"awaitingFunds": 1000,
"totalRequested": 1200,
"accountId": "chrisclassic"
}
'

curl -XPOST localhost:9200/myindex/message/_search?pretty -d'
{
"query": {
"has_parent": {
"parent_type": "account",
"query": {
"match_all": {}
}
}
}
}'

I'm a bit confused - as I had thought this use case was supported?
Thanks
Chris


(Adrien Grand) #2

Can you elaborate a bit more on what you get vs. what you expect?


(Chris Burrell) #3

Hi @jpountz

Sorry - I thought I copied the response in. That was a poor post of mine. The response I get is that there are no children of 'account'. I had assumes that after the curl -XPUT ‘localhost:9200/myindex/message/4?pretty&parent=2&refresh’, seen as '2' is the account, then the search below would return a message.

Does that make sense? If I do a similar search for parent-type 'user' for myindex/account, then I do get an account, but the same does not seem to be true for the account/message parent/child relationship.

Request:

curl -XPOST localhost:9200/myindex/message/_search?pretty -d’
 {
  "query": {
    "has_parent": {
      "parent_type": "account",
      "query": {
        "match_all": {}
      }
    }
  }
}'

Response:

{
"took" : 5,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 0,
"max_score" : null,
"hits" : [ ]
}
}


(Chris Burrell) #4

Anyone? Does that make sense? Could that be a bug (I'm assuming not, with something so basic!)
Thanks
Chris


(Chris Burrell) #5

Hi all

I don't want to believe that such functionality is broken. That would be really odd and surprising, however, my use case is so simple, I would appreciate if someone could take a brief look.

  • Create parent mapping between A -> B, and mapping between B -> C
  • Create child to parent, and grand child to child
  • Elasticsearch fails to return any results for parent_type of B.

Perhaps that's because it doesn't know how to route the query without going down the tree of A?
Thanks
Chris


(system) #6

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.