_source filtering in field collapsing query

I tried field collapsing query with following query DSL:

{
    "query": {
        "match": {
            "Title": "elasticsearch"
        }
    },
    "collapse" : {
        "field" : "Category",
        "inner_hits": {
            "_source":  ["Title", "Url"]
            "name": "top_docs", 
            "size": 10
        }
    }    
}

But got following error message:

 "reason": "[collapse] failed to parse field [inner_hits]",
    "line": 10,
    "col": 24,
    "caused_by": {
      "type": "illegal_argument_exception",
      "reason": "[inner_hits] _source doesn't support values of type: START_ARRAY"
    }

Per https://www.elastic.co/guide/en/elasticsearch/reference/5.3/search-request-inner-hits.html, source filtering is supported in inner_hits options.

Anything wrong in my DSL?

I found the solution myself.

If using source filtering in inner_hits, I must use "include“ pattern as follows:

{
    "query": {
        "match": {
            "Title": "birds"
        }
    },
    "collapse" : {
        "field" : "Category.raw",
        "inner_hits": {
            "_source": {
                "include": ["Title", "Url"]
            },
            "name": "top_docs", 
            "size": 10
        }
    }    
}

Is it by design or a bug?

Anyway, it should be clearly stated in document.

2 Likes

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