我试图弄清楚如何在Elasticsearch索引中总结许多不同的计数。索引中的文档如下所示:
{
'_source': {
'my_field': 'Robert and Alex went with Robert to play in London and then Robert went to London',
'ner': {
'persons': {
'Alex': 1,
'Robert': 3
},
'organizations': {},
'dates': {},
'locations': {
'London': 2
}
}
}
}
如何总结索引中location
,dates
和persons
中所有不同的词?例如,如果另一个文档出现了两次Alex
,我将得到Alex: 3, Robert: 3, ..
答案 0 :(得分:0)
curl -X POST "localhost:9200/yourindex/_search?size=0" -H 'Content-Type: application/json' -d'
{
"aggs" : {
"person_Alex" : { "sum" : { "field" : "person.Alex" } },
"person_Robert" : { "sum" : { "field" : "person.Robert" } },
"person_Alex" : { "sum" : { "field" : "person.Alex" } }
}
}
'
curl -X GET "localhost:9200/yourindex/_search" -H 'Content-Type: application/json' -d'
{
"aggs" : {
"count_Alex" : {
"terms" : { "field" : "person.Alex" }
},
"count_Robert" : {
"terms" : { "field" : "person.Alex" }
}
}
}'
您需要指定字段。