I have category as array type.
I need to get all the distinct categories.
"software",
"development",
"cloud computing",
"project management"
What kind query should I use?
curl -XPUT 'http://localhost:9200/cstest/csproducts/1' -d '
{
"productid":"1",
"productnumber":"123",
"category":["software"]
}
curl -XPUT 'http://localhost:9200/test/products/2' -d '
{
"productid":"2",
"productnumber":"1234",
"category":["software","development"]
}
curl -XPUT 'http://localhost:9200/test/products/3' -d '
{
"productid":"2",
"productnumber":"1234",
"category":["cloud computing","project management"]
}
Here is a search that returns zero docs but the top 100 category terms:
GET /test/csproducts/_search
{
"size":0,
"aggs":{
"allCategories":{
"terms":{
"field":"category",
"size":100
}
}
}
}
Thanks for the reply.
When the category is "cloud computing"
It is being considered as a two different categories.
It returns something like -
"aggregations" : {
"allCategories" : {
"buckets" : [ {
"key" : "software",
"doc_count" : 2
}, {
"key" : "cloud",
"doc_count" : 1
}, {
"key" : "computing",
"doc_count" : 1
}, {
"key" : "development",
"doc_count" : 1
}, {
"key" : "management",
"doc_count" : 1
}, {
"key" : "project",
"doc_count" : 1
} ]
}
}
I tried adding "position_offset_gap": 100, but did not help.