Matt
Matt

Reputation: 1343

ElasticSearch facet results without document

I'm trying to get the histogram for some events I have indexed, but I only want in the response the 'facet results' and not the search + facet results.

This is an example of the query I'm running:

curl -XGET 'http://localhost:9200/main/events/_search?pretty=true' -d '
{
   "facets" : {
    "histo1" : {
       "query" : {
            "query_string" : {"query":"*:*"}
        },
         "date_histogram" : {
            "field" : "time",
            "interval" : "minute"
        }
    }
  }
}
'

So in the result I want to have just the

"facets" : {
"histo1" : {
  "_type" : "date_histogram",
  "entries" : [ {
    "time" : 1337700000,
    "count" : 76
  } ]
}

part, without all the documents that matched the query.

Is this possible?

Thanks a lot.

Upvotes: 16

Views: 4075

Answers (1)

imotov
imotov

Reputation: 30163

You can use count search_type:

curl -XGET 'http://localhost:9200/main/events/_search?search_type=count&pretty=true' -d '
{
  "facets" : {
    "histo1" : {
       "query" : {
            "query_string" : {"query":"*:*"}
        },
         "date_histogram" : {
            "field" : "time",
            "interval" : "minute"
        }
    }
  }
}
' 

Alternatively, you can set "size":0 to your query, but it will be less efficient:

curl -XGET 'http://localhost:9200/main/events/_search?pretty=true' -d '
{
  "facets" : {
    "histo1" : {
       "query" : {
            "query_string" : {"query":"*:*"}
        },
         "date_histogram" : {
            "field" : "time",
            "interval" : "minute"
        }
    }
  },
  "size":0
}
'

Upvotes: 28

Related Questions