[bool] query does not support [fiter]

below is index mapping

{
  "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

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:

{
  "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!

Please format your code, logs or configuration files using </> icon as explained in this guide 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

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.

I solved it in two other ways
method1

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:

method2

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"
      }
    }
  }
}

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