# Filter on script hit result

**URL:** <https://discuss.elastic.co/t/filter-on-script-hit-result/279960>\
**Category:** Elasticsearch\
**Tags:** painless\
**Created:** [July 29, 2021, 9:59am UTC](https://discuss.elastic.co/t/filter-on-script-hit-result/279960 "2021-07-29T09:59:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Giovanni\_Di\_Lembo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/giovanni_di_lembo/32/45714_2.png) [@Giovanni\_Di\_Lembo](https://discuss.elastic.co/u/Giovanni_Di_Lembo)\
**Post date:** [July 29, 2021, 9:59am UTC](https://discuss.elastic.co/t/filter-on-script-hit-result/279960/1 "2021-07-29T09:59:55Z")

</div>

Hi all and sorry for my poor english.  
I'm filtering my index cpes using script (painless).  
As a a result , I have hits with null values and I need to exclude those hits.  
I've done this query, but I cannot find a way to excludes null hits

```auto
GET cpes/_search
{
  "script_fields": {
    "cpeBox_with_profiles_grather_than_1": {
      "script": {
        "lang": "painless",
        "source": "if (params['_source'].profiles.size()>10) return params['_source'].cpeBoxId; "
      }
    }
  }  
}

```

Result is

```auto
{
  "took" : 4,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 10000,
      "relation" : "gte"
    },
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "cpes",
        "_type" : "_doc",
        "_id" : "12654213",
        "_score" : 1.0,
        "fields" : {
          "cpeBox_with_profiles_grather_than_1" : [
            null
          ]
        }
      },
      {
        "_index" : "cpes",
        "_type" : "_doc",
        "_id" : "12651607",
        "_score" : 1.0,
        "fields" : {
          "cpeBox_with_profiles_grather_than_1" : [
            null
          ]
        }
      },
      {
        "_index" : "cpes",
        "_type" : "_doc",
        "_id" : "12386833",
        "_score" : 1.0,
        "fields" : {
          "cpeBox_with_profiles_grather_than_1" : [
            null
          ]
        }
      },
      {
        "_index" : "cpes",
        "_type" : "_doc",
        "_id" : "12647464",
        "_score" : 1.0,
        "fields" : {
          "cpeBox_with_profiles_grather_than_1" : [
            null
          ]
        }
      },
      {
        "_index" : "cpes",
        "_type" : "_doc",
        "_id" : "12649048",
        "_score" : 1.0,
        "fields" : {
          "cpeBox_with_profiles_grather_than_1" : [
            null
          ]
        }
      },
      {
        "_index" : "cpes",
        "_type" : "_doc",
        "_id" : "12651604",
        "_score" : 1.0,
        "fields" : {
          "cpeBox_with_profiles_grather_than_1" : [
            null
          ]
        }
      },
      {
        "_index" : "cpes",
        "_type" : "_doc",
        "_id" : "12657472",
        "_score" : 1.0,
        "fields" : {
          "cpeBox_with_profiles_grather_than_1" : [
            null
          ]
        }
      },
      {
        "_index" : "cpes",
        "_type" : "_doc",
        "_id" : "12654692",
        "_score" : 1.0,
        "fields" : {
          "cpeBox_with_profiles_grather_than_1" : [
            null
          ]
        }
      },
      {
        "_index" : "cpes",
        "_type" : "_doc",
        "_id" : "12659253",
        "_score" : 1.0,
        "fields" : {
          "cpeBox_with_profiles_grather_than_1" : [
            null
          ]
        }
      },
      {
        "_index" : "cpes",
        "_type" : "_doc",
        "_id" : "12660748",
        "_score" : 1.0,
        "fields" : {
          "cpeBox_with_profiles_grather_than_1" : [
            null
          ]
        }
      }
    ]
  }
}

```

What I need is to exclude hits with cpeBox\_with\_profiles\_grather\_than\_1= null

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [August 26, 2021, 10:00am UTC](https://discuss.elastic.co/t/filter-on-script-hit-result/279960/2 "2021-08-26T10:00:46Z")

</div>

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