Search code examples
elasticsearchjoinparent

How to query an elasticsearch join field name?


Say I have a parent document with the following structure:

{
   "join": {
       "name": "parent"
   }
   "foo": 3
}

How could I query all documents where the join name is parent?

I have tried the naive approach:

GET my-index/_search
{
    "query" : {
        "term": { "join.name" : "parent" }
    }
}

But it returns 0 results. What am I missing?


Solution

  • You don't have to append .name to the join field.

    GET my-index/_search
    {
        "query" : {
            "term": { "join" : "parent" }
        }
    }