Question regarding multiple filters

I would like to find documents through POST method using multiple filters. Below code throws the error "Expected field name but got START_OBJECT "range"]

This should retrieve documents which has "activity_name" field within certain time range. Please suggest me how can we specify it?

{
    "fields": [
        "message",
        "activity_name",
        "activity_id"
    ],  
    query: {
        "query_string": {
            "query": "type:\"sample\""
            }
    },
    filter : {
        exists : { "field" : "activity_name" },
        "range": {
                "@timestamp": {
                    "from": 1460533654532,
                    "to": 1460533954531
                }
            }
    }
}

I'm pretty sure you just need to wrap the exists and range filters in an and:

{
    "fields": [
        "message",
        "activity_name",
        "activity_id"
    ],  
    query: {
        "query_string": {
            "query": "type:\"sample\""
            }
    },
    filter : {
        "and": [
            {"exists" : { "field" : "activity_name" }},
            {"range": {
                "@timestamp": {
                    "from": 1460533654532,
                    "to": 1460533954531
                }
            }
        }]
    }
}
1 Like

Thanks. It worked