Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 546
Matt Avatar asked May 23 '12 08:05

Matt


1 Answers

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
}
'
like image 111
imotov Avatar answered Sep 30 '22 09:09

imotov