0
votes

I have an elastic search schema of the kind shown below

{
  "customer": {
    "properties": {
        "id": {"type": "string", "index": "not_analyzed"}
    }
  }
}

{
  "activity": {
    "parent": {
      "type": "customer"
    },
    "routing": {
        "required": true,
        "path": "customer.id"
    },
    "properties": {
        ...
        // The parent object is included on activity
        "customer": {
            "properties": {
                "id": {"type": "string", "index": "not_analyzed"}
            }
          }
    }
  }
}

Where, customers have activities and activities are children of customer type. I also have the customer available directly on the activity type.

If I now write a terms filter against the activity type

{
    "terms": {
        "field": "customer.id"
    }
}

Which reads as - bucket all activities belonging to the same customer.

Surprisingly, this buckets activity.id instead of activity.customer.id. I'm stumped. Really truly.

I assumed this has something to do with the parent-child relation? I was able to get what I want by doing

{
    "terms": {
        "field": "_parent"
    }
}

I don't understand this. Can someone point out what I'm doing wrong?

1

1 Answers

1
votes

This problem has been recently described in this blog article and is one of the reasons why the ES 2.0 will undergo a big refactoring around mappings. In short, the issue here is that in your mapping, customer is both a type name and a field name, so customer.id can refer to either the id field of the customer type or the id field of the customer object in the activity type.

So if you use the following fully-qualified field name instead, it should work as expected:

{
    "terms": {
        "field": "activity.customer.id"
    }
}