Loop over inner_hits within post_filter via script

This is how the response looks like:

{
  "hits" : {
    "hits" : [
      {
        "_index" : "myindex",
        "_type" : "_doc",
        "_id" : "7201e7f0-882f-4184-bdda-71302b8c28d3",
        "_source" : {...},
        "inner_hits" : {
          "inner_hits_1" : {
            "hits" : {
              "total" : {
                "value" : 1,
                "relation" : "eq"
              },
              "hits" : [
                {
                  "_index" : "myindex",
                  "_type" : "_doc",
                  "_id" : "7201e7f0-882f-4184-bdda-71302b8c28d3",
                  "_nested" : {
                    "field" : "transcript",
                    "offset" : 1
                  },
                  "_source" : {
                    "phrase" : "good afternoon"
                    "conv_id" : 1
                  },
                  "highlight" : {
                    "transcript.phrase" : [
                      "<HIGHLIGHT>good<HIGHLIGHT/> afternoon"
                    ]
                  }
                }
              ]
            }
          },
          "inner_hits_2" : {...},
          "inner_hits_3" : {...}
        }
      }
    ]
  }
}

How do I loop over all the inner_hits within post_filter via script ?
Something like this:

GET myindex/_search
{
  "query": {...},
  "post_filter": {
    "script": {
      "script": {
        "lang": "painless",
        "source": """

          // loop over inner_hits here and filter documents
        
        """
      }
    }
  }
}

@dadoonet @Christian_Dahlqvist

Kindly suggest if this is possible.

Regards,

Please note that this forum is manned exclusively by volunteers, out of which some may work for Elastic. There are therefore no SLAs offered and not even any guarantee that you will receive a response (although this is not very common). As it is a community forum it is by many considered rude to ping people not already involved in the thread.

Most people, including myself, tend to respond to topics where we have knowledge or experience and let others respond to topics that match their profile and interests. What makes you believe I have any input on this topic? Have you ever seen me respond to topics around inner hits and advanced script scoring/filtering?

Apologies for that Chris. Will be mindful of this going forward. :slightly_smiling_face:

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