How to filter out results using scriptQuery?

I am trying to filter the results returned by Elasticsearch and I am using painless script, since the data that needs to be used is on the index. My mapping looks like this:

{
  "took": 100,
  "timed_out": false,
  "_shards": {
    "total": 3,
    "successful": 3,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 1,
      "relation": "eq"
    },
    "max_score": 0.0,
    "hits": [
      {
        "_index": "automobiles",
        "_type": "_doc",
        "_id": "13",
        "_score": 0.0,
        "_source": {
          "listResults": [
            {
              "id": 10,
              "array1": [
                "text1",
                "text2"
              ],
              "array2": [
                "textA",
                "textB"
              ]
            }
          ]
        }
      }
    ]
  }
}

The result of that script is added via new ScriptQuery, which is added to bool query to filter results.

The error I am getting is due to the painless script since I have been able to confirm the rest works. If within the painless script I simply write for debugging purposes "return true", it will return all the documents. However for my task I want to filter where in the es index listResults has id with value 10. If that value is 10 it should return true, otherwise it should return false. From what I've read in the documentation that should mark which documents to include in the results and which results should not be returned. However this is not working, I keep getting 0 results or a compile error. The compile error doesn't show me what is wrong as I've compared to my mapping and should be working.

I welcome any suggestions.

Thanks.

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