Bonjour,
j'ai essayé de faire une requête ES avec une aggregation, mais je n'ai pas le résultat que je veux.
c'est certainement ma requête n'est pas bonne.
voilà mon index:
DELETE test
PUT test
{
"mappings": {
"test": {
"properties": {
"id": {
"type": "long"
},
"tags": {
"properties": {
"cnt": {
"type": "long"
},
"id": {
"type": "text",
"fielddata": true,
"fields": {
"keyword": {
"type": "keyword"
}
}
},
"label": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
}
}
}
}
},
"title": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
}
}
}
}
}
}
}
POST _bulk
{ "index" : { "_index" : "test", "_type" : "test", "_id" : "1" } }
{ "id": 1, "title" : "cyber securité","tags": [{"id": "1","cnt": 8,"label": "categorie 1"},{"id": "2","cnt": 6,"label": "categorie 2"},{"id": "3","cnt": 4,"label": "categorie 3"}]}
{ "index" : { "_index" : "test", "_type" : "test", "_id" : "2" } }
{ "id": 2, "title" : "cybersécurité","tags": [{"id": "1","cnt": 8,"label": "categorie 1"},{"id": "2","cnt": 6,"label": "categorie 2"},{"id": "3","cnt": 4,"label": "categorie 3"}] }
{ "index" : { "_index" : "test", "_type" : "test", "_id" : "3" } }
{ "id": 3, "title" : "technicien bigdata","tags": [{"id": "1","cnt": 8,"label": "categorie 1"},{"id": "2","cnt": 6,"label": "categorie 2"},{"id": "3","cnt": 4,"label": "categorie 3"}] }
{ "index" : { "_index" : "test", "_type" : "test", "_id" : "4" } }
{ "id": 4, "title" : "fullstack","tags": [{"id": "1","cnt": 8,"label": "categorie 1"},{"id": "2","cnt": 6,"label": "categorie 2"},{"id": "3","cnt": 4,"label": "categorie 3"}] }
{ "index" : { "_index" : "test", "_type" : "test", "_id" : "5" } }
{ "id": 5, "title" : "aafullstack", "tags":[] }
{ "index" : { "_index" : "test", "_type" : "test", "_id" : "6" } }
{ "id": 6, "title" : "6fullstack", "tags":[] }
{ "index" : { "_index" : "test", "_type" : "test", "_id" : "7" } }
{ "id": 7, "title" : "7fullstack", "tags":[] }
ma requête:
GET test/_search
{
"size": 0,
"aggs": {
"test": {
"filter": {
"range": {
"tags.cnt":{
"from": 4
}
}
},
"aggs": {
"names": {
"terms": {
"field": "tags.id",
"size": 10
}
}
}
}
}
}
et le résultat:
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 7,
"max_score": 0,
"hits": []
},
"aggregations": {
"test": {
"doc_count": 4,
"names": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "1",
"doc_count": 4
},
{
"key": "2",
"doc_count": 4
},
{
"key": "3",
"doc_count": 4
}
]
}
}
}
}
mais ce que je veux avoir en sortie:
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 7,
"max_score": 0,
"hits": []
},
"aggregations": {
"test": {
"doc_count": 4,
"names": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "3",
"doc_count": 4
}
]
}
}
}
}
si quelqu'un peut m'aider !
merci