1

I'm attempting to do a count query such that I return the number of unsuccessful attempts to log into my system within the last 10 minutes. I created this query:

{
  "term": {
    "success":false
  },
  "range": {
    "_timestamp": {
      "gt": "now-10m"
    }
  }
}

However, this returns all of the unsuccessful attempts for any time, disregarding the range filter in my query. Am I structuring this query correctly? The query works when I do a search with terms and ranges.

In other words, the output of the above query and curl -XGET localhost:9200/application/_count is the same (I have only tested unsuccessful attempts).

2 Answers 2

1

Try using the search_type parameter instead of using the countAPI. This is actually preferred:

curl -XGET localhost:9200/application/_search&search_type=count -d'{
    query:....
}'

Documentation: http://www.elasticsearch.org/guide/reference/api/search/search-type/

Sign up to request clarification or add additional context in comments.

Comments

0

The range is a filter, so I think you have to create a filtered query to take it correctly into account :

{
  "filtered": {
    "query": {
      "term": {
        "success":false
      },
    },
    "filter: {
      "range": {
        "_timestamp": {
          "gt": "now-10m"
        }
      }
    }
  }
}

3 Comments

This doesn't work and still gives me output of count: 4, the same as a GET request to localhost:9200/application/_count
I think I get it. The range is only a filter. You have to use a filtered query. I will update my answer.
Same issue... :( I was able to successfully get the correct results during a search query with my parameters, but count will not accept them and only goes after term.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.