Код: Выделить всё
{"username": "tom",
"dept" : "SE",
"location": "NY"
}
{"username": "john",
"dept" : "SE",
"location": "MA"
}
{"username": "tom",
"dept" : "DQ",
"location": "NY"
}
{"username": "mary",
"dept" : "TY",
"location": "TA"
}
Код: Выделить всё
select distinct username from my_index
Код: Выделить всё
["tom", "john", "mary"]
И сделал запрос
Код: Выделить всё
query = {
"size": 0,
"aggs": {
"unique_username": {
"terms": {
"field": "username.keyword",
"size": 200
}
}
}
}
es.search(index="my_index", body=query)
Код: Выделить всё
{'took': 64, 'timed_out': False, '_shards': {'total': 5, 'successful': 5, 'skipped': 0, 'failed': 0}, 'hits': {'total': 3200, 'max_score': 0.0, 'hits': []}, 'aggregations': {'unique_username': {'buckets': []}}}
Код: Выделить всё
{'buckets': []}
Также, когда я выполняю https://localhost:9200/my_index/_search ... rue&size=5
, я получаю результат
{
Код: Выделить всё
"took": 18,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 3200,
"max_score": 1,
"hits": [
{
"_index": "my_index_9y9f2b4e-5t90-44a2-b444-t7537fr6656b",
"_type": "my_table",
"_id": "1",
"_score": 1,
"_source": {
"username": "tom",
"dept": "SE",
"location": "NY"
}
},
{
"_index": "my_index_9y9f2b4e-5t90-44a2-b444-t7537fr6656b",
"_type": "my_table",
"_id": "2",
"_score": 1,
"_source": {
"username": "john",
"dept": "SE",
"location": "MA"
}
},
{
"_index": "my_index_9y9f2b4e-5t90-44a2-b444-t7537fr6656b",
"_type": "my_table",
"_id": "3",
"_score": 1,
"_source": {
"username": "tom",
"dept": "DQ",
"location": "NY"
}
},
{
"_index": "my_index_9y9f2b4e-5t90-44a2-b444-t7537fr6656b",
"_type": "my_table",
"_id": "4",
"_score": 1,
"_source": {
"username": "mary",
"dept": "TY",
"location": "TA"
}
}
]
}
}
Подробнее здесь: https://stackoverflow.com/questions/683 ... pty-result