1

I have documents from different applications in one index, with application name a field in each document. Now I want to count the number of documents per application per day. The application name is in string format, so I cannot use a filter term for it. While the below GET query does the filtering per application

{
  "query": {
    "filtered": {
      "query": {
        "query_string": {
           "query": "+environmentType:prod +application:app1",
           "analyze_wildcard": true
        }
      }
    }
  }
}

and I can use this aggregation for simple daily counts

{
  "aggs": {
    "simpleDatehHistogram": {
      "date_histogram": {
        "field": "timestamp",
        "interval": "day"
      }
    }
  }
}

I don't seem to be able to combine them so that the application filter is applied to my aggregation results.

This is the mapping of my index.

{
  "myIndex" : {
    "mappings" : {
      "myType" : {
        "properties" : {
          "application" : {
            "type" : "string"
          },
          "environmentType" : {
            "type" : "string"
          },
          "event" : {
            "properties" : {
              "Id" : {
                "type" : "long"
              },
              "documentId" : {
                "type" : "string"
              },
            }
          },
          "hostname" : {
            "type" : "string"
          },
          "id" : {
            "type" : "string"
          },
          "timestamp" : {
            "type" : "date",
            "format" : "dateOptionalTime"
          },
          "timestampEpoch" : {
            "type" : "long"
          },
          "type" : {
            "type" : "string"
          },
          "version" : {
            "type" : "string"
          }
        }
      }
    }
  }
}

1 Answer 1

2

Use this to combine them:

{
   "size":0,
   "query":{
      "filtered":{
         "query":{
            "query_string":{
               "query":"+environmentType:prod +application:app1",
               "analyze_wildcard":true
            }
         }
      }
   },
   "aggs":{
      "simpleDatehHistogram":{
         "date_histogram":{
            "field":"timestamp",
            "interval":"day"
         }
      }
   }
}
Sign up to request clarification or add additional context in comments.

5 Comments

this was the first thing I tried actually, but the results are identical regardless of the name of my application, so I guess that filter is not applied...
Can you just post mapping of your index. GET index/type/_mapping
I just tried above query and it did bring me aggregation buckets on the basis of query applied above. Can you just elaborate more on this .
Okay, I just tried to do an aggregation on my applications only and found out that application names with '-' are not divided as I expected, so with application names 'app_one', and 'app_two', I get three buckets of 'app', 'one', and 'two', and query_string on either one returns the 'app' bucket.
Happy to help :)

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.