Facets
Facets provide aggregated data based on a search
query. In the simplest case, a terms facet can return facet counts for various
facet values for a specific field. ElasticSearch supports more facet
implementations, such as statistical or date histogram facets.
TERM
Facets
Allow to specify field facets that return the N most
frequent terms.
Example:
PUT
Method:
http://localhost:9200/mobiles/
POST
Method:
http://localhost:9200/mobiles/nokia/_bulk
{"index":{"_id": 1}}
{"name":"lumia 510"}
{"index":{"_id": 2}}
{"name":"lumia 520"}
{"index":{"_id": 3}}
{"name":"lumia 625"}
{"index":{"_id": 4}}
{"name":"lumia 720"}
http://localhost:9200/mobiles/samsung/_bulk
{"index":{"_id": 1}}
{"name":"core"}
{"index":{"_id": 2}}
{"name":"s2"}
{"index":{"_id": 3}}
{"name":"s4"}
{"index":{"_id": 4}}
{"name":"note"}
http://localhost:9200/mobiles/micromax/_bulk
{"index":{"_id": 1}}
{"name":"bolt"}
{"index":{"_id": 2}}
{"name":"canvas"}
http://localhost:9200/mobiles/_search?pretty=true
{
"query" : { "query_string" : {"query" :
"*a*"} },
"facets"
: {
"type" : { "terms" : {"field" :
"_type"} }
}
}
Results:
{
"took": 49,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"failed": 0
},
"hits": {
"total": 5,
"max_score": 1,
"hits": [
{
"_index": "mobiles",
"_type": "nokia",
"_id": "1",
"_score": 1,
"_source": {
"name": "lumia 510"
}
},
{
"_index": "mobiles",
"_type": "nokia",
"_id": "2",
"_score": 1,
"_source": {
"name": "lumia 520"
}
},
{
"_index": "mobiles",
"_type": "nokia",
"_id": "3",
"_score": 1,
"_source": {
"name": "lumia 625"
}
},
{
"_index": "mobiles",
"_type": "nokia",
"_id": "4",
"_score": 1,
"_source": {
"name": "lumia 720"
}
},
{
"_index": "mobiles",
"_type": "micromax",
"_id": "2",
"_score": 1,
"_source": {
"name": "canvas"
}
}
]
},
"facets": {
"type": {
"_type": "terms",
"missing": 0,
"total": 5,
"other": 0,
"terms": [
{
"term": "nokia",
"count": 4
},
{
"term": "micromax",
"count": 1
}
]
}
}
TERM Facets with OrderingTERM Facets with Excluding Terms
TERM Facets with Term Scripts
TERM Facets with Multi Fields
TERM Facets with Script Field
No comments:
Post a Comment