# \[bool\] query does not support \[fiter\]

**URL:** <https://discuss.elastic.co/t/bool-query-does-not-support-fiter/143833>\
**Category:** Elasticsearch\
**Created:** [August 10, 2018, 8:29am UTC](https://discuss.elastic.co/t/bool-query-does-not-support-fiter/143833 "2018-08-10T08:29:16Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dingaimin](https://avatars.discourse-cdn.com/v4/letter/d/d07c76/32.png) [@dingaimin](https://discuss.elastic.co/u/dingaimin)\
**Post date:** [August 10, 2018, 8:29am UTC](https://discuss.elastic.co/t/bool-query-does-not-support-fiter/143833/1 "2018-08-10T08:29:16Z")

</div>

below is index mapping

```auto
{
  "lm_dsp_data_search_funnel-2018.08.10": {
    "mappings": {
      "doc": {
        "properties": {
          "@timestamp": {
            "type": "date"
          },
          "@version": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "abtest": {
            "type": "keyword"
          },
          "adlist": {
            "type": "nested",
            "properties": {
              "promotionid": {
                "type": "integer"
              },
              "sn": {
                "type": "integer"
              }
            }
          },
          "adxid": {
            "type": "keyword"
          },
          "age": {
            "type": "integer"
          },
          "deviceidmd5": {
            "type": "keyword"
          },
          "displocal1": {
            "type": "integer"
          },
          "displocal2": {
            "type": "integer"
          },
          "escount": {
            "type": "long"
          },
          "gender": {
            "type": "integer"
          },
          "interest": {
            "type": "integer"
          },
          "mediaid": {
            "type": "integer"
          },
          "os": {
            "type": "integer"
          },
          "sid": {
            "type": "keyword"
          },
          "sidcount": {
            "type": "integer"
          },
          "slotid": {
            "type": "integer"
          },
          "stime": {
            "type": "long"
          },
          "styleids": {
            "type": "integer"
          },
          "tags": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "userip": {
            "type": "keyword"
          }
        }
      }
    }
  }
}

```

expression is below

```auto
GET lm_dsp_data_search_funnel-2018.08.10/_search
{
  "size": 10, 
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "adxid": "u-2cbc34ryk3v43nkdq9g"
          }
        },
        {
          "range": {
            "stime": {
              "gte": 1533859200000,
              "lte": 1533873600000
            }
          }
        }
      ],
      "filter": {
        "script": {
          "script": "doc['adlist'].values.length > 0"
        }
      }
    }
  }, 
  "aggs": {
    "sn_count": {
      "sum": {
        "field": "sidcount"
      }
    }
  }
}

```

I want to add a query is that adlist.size \> 0 .  
here is the response:

```auto
{
  "error": {
    "root_cause": [
      {
        "type": "script_exception",
        "reason": "runtime error",
        "script_stack": [
          "org.elasticsearch.search.lookup.LeafDocLookup.get(LeafDocLookup.java:81)",
          "org.elasticsearch.search.lookup.LeafDocLookup.get(LeafDocLookup.java:39)",
          "doc['adlist'].length > 0",
          " ^---- HERE"
        ],
        "script": "doc['adlist'].length > 0",
        "lang": "painless"
      }
    ],
    "type": "search_phase_execution_exception",
    "reason": "all shards failed",
    "phase": "query",
    "grouped": true,
    "failed_shards": [
      {
        "shard": 0,
        "index": "lm_dsp_data_search_funnel-2018.08.10",
        "node": "gIcfga4kTZq7A4XI1dHC0A",
        "reason": {
          "type": "script_exception",
          "reason": "runtime error",
          "script_stack": [
            "org.elasticsearch.search.lookup.LeafDocLookup.get(LeafDocLookup.java:81)",
            "org.elasticsearch.search.lookup.LeafDocLookup.get(LeafDocLookup.java:39)",
            "doc['adlist'].length > 0",
            " ^---- HERE"
          ],
          "script": "doc['adlist'].length > 0",
          "lang": "painless",
          "caused_by": {
            "type": "illegal_argument_exception",
            "reason": "No field found for [adlist] in mapping with types []"
          }
        }
      }
    ]
  },
  "status": 500
}

```

thanks for your answer!

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [August 10, 2018, 9:15am UTC](https://discuss.elastic.co/t/bool-query-does-not-support-fiter/143833/2 "2018-08-10T09:15:18Z")

</div>

Please format your code, logs or configuration files using `</>` icon as explained in [this guide](https://discuss.elastic.co/t/about-the-elasticsearch-category/21) and not the citation button. It will make your post more readable.

Or use markdown style like:

````
```
CODE
```

````

This is the icon to use if you are not using markdown format:

![image](https://us1.discourse-cdn.com/elastic/original/3X/7/e/7e6e239431ec2d71cbf1beef741f2e93e7cc762c.jpg)

There's a live preview panel for exactly this reasons.

Lots of people read these forums, and many of them will simply skip over a post that is difficult to read, because it's just too large an investment of their time to try and follow a wall of badly formatted text.  
If your goal is to get an answer to your questions, it's in your interest to make it as easy to read and understand as possible.  
Please update your post.

Here you are most likely using an old version may be?

---

<div class="post-metadata">

**Author:** ![dingaimin](https://avatars.discourse-cdn.com/v4/letter/d/d07c76/32.png) [@dingaimin](https://discuss.elastic.co/u/dingaimin)\
**Post date:** [August 10, 2018, 9:25am UTC](https://discuss.elastic.co/t/bool-query-does-not-support-fiter/143833/3 "2018-08-10T09:25:58Z")

</div>

> [@dadoonet](#):
>
> There's a live preview panel for exactly this reasons.
> 
> Lots of people read these forums, and many of them will simply skip over a post that is difficult to read, because it's just too large an investment of their time to try and follow a wall of badly formatted text.  
> If your goal is to get an answer to your questions, it's in your interest to make it as easy to read and understand as possible.  
> Please update your post.
> 
> Here you are most likely using an old version may be?

thanks, i will do that.

---

<div class="post-metadata">

**Author:** ![dingaimin](https://avatars.discourse-cdn.com/v4/letter/d/d07c76/32.png) [@dingaimin](https://discuss.elastic.co/u/dingaimin)\
**Post date:** [August 10, 2018, 11:07am UTC](https://discuss.elastic.co/t/bool-query-does-not-support-fiter/143833/4 "2018-08-10T11:07:58Z")

</div>

I solved it in two other ways  
method1

```auto
GET lm_dsp_data_search_funnel-2018.08.10/_search
{
  "size": 0,
  "query": {
    "bool": {
      "must": [
        {
          "term": {
            "adxid": {
              "value": "u-2cbc34ryk3v43nkdq9g"
            }
          }
        },
        {
          "range": {
            "stime": {
              "gte": 1533859200000,
              "lte": 1533898800000
            }
          }
        },
        {
          "nested" : {
            "path" : "adlist",
            "score_mode" : "none",
            "query" : {
              "exists":{"field":"adlist"}
            }
          }
        }
      ]
    }
  },
  "aggs": {
    "count": {
      "sum": {
        "field": "sidcount"
      }
    }
  }
}

```

api documentation:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/4/b/4b464c1dd08d31ad35054c34b352a5e2a0633dbf.png)

method2

```auto
GET lm_dsp_data_search_funnel-2018.08.10/_search
{
  "size": 0,
  "query": {
    "bool": {
      "must": [
        {
          "term": {
            "adxid": {
              "value": "u-2cbc34ryk3v43nkdq9g"
            }
          }
        },
        {
          "range": {
            "stime": {
              "from": 1533891139904,
              "to": null,
              "include_lower": false,
              "include_upper": false,
              "boost": 1
            }
          }
        },
        {
          "nested" : {
            "path" : "adlist",
            "score_mode" : "none",
            "query" : {
                "bool" : {
                    "must" : [
                      { "range" : {"adlist.promotionid" : {"gte" : "0"}} }
                    ]
                }
            }
          }
        }
      ]
    }
  },
  "aggs": {
    "count": {
      "sum": {
        "field": "sidcount"
      }
    }
  }
}

```

---

<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:** [September 7, 2018, 11:08am UTC](https://discuss.elastic.co/t/bool-query-does-not-support-fiter/143833/5 "2018-09-07T11:08:03Z")

</div>

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