Нет прямого способа сделать это в elasti c search. Самое близкое, что можно сделать, - это использовать многовременные векторы
Запрос
POST /index51/_mtermvectors
{
"ids" : ["1", "2"], --> Ids of all documents (_id)
"parameters": {
"fields": [
"text"
],
"term_statistics": true
}
}
Он вернет список всех документов со статистикой для каждого слова в поле
Результат:
{
"docs" : [
{
"_index" : "index51",
"_type" : "_doc",
"_id" : "1",
"_version" : 2,
"found" : true,
"took" : 3,
"term_vectors" : {
"text" : {
"field_statistics" : {
"sum_doc_freq" : 7,
"doc_count" : 3,
"sum_ttf" : 7
},
"terms" : {
"another" : {
"doc_freq" : 2,
"ttf" : 2,
"term_freq" : 1,
"tokens" : [
{
"position" : 0,
"start_offset" : 0,
"end_offset" : 7
}
]
},
"test" : {
"doc_freq" : 3,
"ttf" : 3,
"term_freq" : 1,
"tokens" : [
{
"position" : 2,
"start_offset" : 16,
"end_offset" : 20
}
]
},
"twitter" : {
"doc_freq" : 2,
"ttf" : 2,
"term_freq" : 1,
"tokens" : [
{
"position" : 1,
"start_offset" : 8,
"end_offset" : 15
}
]
}
}
}
}
},
{
"_index" : "index51",
"_type" : "_doc",
"_id" : "2",
"_version" : 1,
"found" : true,
"took" : 2,
"term_vectors" : {
"text" : {
"field_statistics" : {
"sum_doc_freq" : 7,
"doc_count" : 3,
"sum_ttf" : 7
},
"terms" : {
"test" : {
"doc_freq" : 3,
"ttf" : 3,
"term_freq" : 1,
"tokens" : [
{
"position" : 0,
"start_offset" : 0,
"end_offset" : 4
}
]
}
}
}
}
}
]
}
Идентификаторы всех документов можно получить с помощью scroll api