How to facet on parent property - what's wrong with this code?


(Alfonso Mateos) #1

I've got this mapping in a parent-child relation between myParent and myChild:

{
"myParent": {
	"properties": {
		"parentCode": {"type": "string"},
		"parentDescriptor": {"type": "string"}
	}
},
"myChild": {
  "_parent": {
   "type": "myParent"
  },
	"properties": {
		"childCode": {"type": "string"},
		"childDescriptor": {"type": "string"}
	}
}

}
}

I use this query to get facets both on child and parent fields, against the url http://localhost:9200/myIndex/myChild

{
  "query": {
    "has_parent": {
      "type": "myChild", 
      "inner_hits": {},
      "query": {
        "match_all": {
        }
      }
    }
  },
    "facets" : {
        "childCode" : {
            "terms" : {
                "field" : "childCode",
                "size" : 2147483647
            }
        },
	"parentCode": {
          "terms": {
              "field": "parentCode",
                "size" : 2147483647
          }
	}
    }
}

I get correct results from the query (every child includes its parent inside inner_hits), but the facet for parentCode is always ZERO. I've tried to name the terms.field for that facet as myParent.parentCode, inner_hits.myParent.parentCode but I cannot get that facet.

Can you tell me how can I get it?
Thanks in advance.


(system) #2

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