Aggregating on highlight


(Sofiane Chenna) #1

Hi ,
I have a query that returns a highlight fields , i wanna aggregate the fields returned by the query ( see code )

      {
            "query" : {
                "query_string" : {
                    "query" : "*so*",
                    "fields": ["MemberFname", "TopicLabel"] 
                }
            },
            "highlight": {           
             	 "pre_tags" : ["", ""],
            "post_tags" : ["", ""],
                "fields" : {
                    "MemberFname" : {},          
                     "TopicLabel": {}
                }
            }

    }

i want to aggregate the fields "MemberFname" and "TopicLabel" to return unique values of these fields
any idea how to do it ?
thanks


(Mark Harwood) #2

Aggregations work on the raw values of documents (or values mutated by a script) and not the outputs of a highlighter.
If these fields are single-value fields then a straight-forward terms aggregation on the field value would work otherwise you'd need to use a terms agg with script to filter the multiple values in matching docs to just those values that contain so as in your query.


(Sofiane Chenna) #3

Thanks for your answer , but my problem is that when a "MemberFname" is matched with the query , the query returns the both fields (MemberFname and TopicLabel ) in terms aggregation , and i want to return only the field that matched the query.

Thanks


(system) #4

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