Intuicja: W SQL żargonie:
Select distinct full_name from authors;
jest równoważna
Select full_name from authors group by full_name;
Tak, możemy użyć składni grupy/kruszywa w ElasticSearch znaleźć odrębne wpisy .
przyjęto następujące założenia jest struktura przechowywane w elastycznym wyszukiwania:
[{
"author": "Brian Kernighan"
},
{
"author": "Charles Dickens"
}]
Co nie działa: Plain agregacja
{
"aggs": {
"full_name": {
"terms": {
"field": "author"
}
}
}
}
mam następujący błąd:
{
"error": {
"root_cause": [
{
"reason": "Fielddata is disabled on text fields by default...",
"type": "illegal_argument_exception"
}
]
}
}
Co pracował jak czar: dołączanie .keyword z polem
{
"aggs": {
"full_name": {
"terms": {
"field": "author.keyword"
}
}
}
}
a wyjście próbki mogą być:
{
"aggregations": {
"full_name": {
"buckets": [
{
"doc_count": 372,
"key": "Charles Dickens"
},
{
"doc_count": 283,
"key": "Brian Kernighan"
}
],
"doc_count": 1000
}
}
}
wskazówka Bonus:
Załóżmy, że pole jest w que stion jest zagnieżdżony w następujący sposób:
[{
"authors": [{
"details": [{
"name": "Brian Kernighan"
}]
}]
},
{
"authors": [{
"details": [{
"name": "Charles Dickens"
}]
}]
}
]
Teraz poprawne zapytania staje:
{
"aggregations": {
"full_name": {
"aggregations": {
"author_details": {
"terms": {
"field": "authors.details.name"
}
}
},
"nested": {
"path": "authors.details"
}
}
},
"size": 0
}
co robi FULL_NAME oznacza? – neustart47
@ neustart47 full_name to tylko nazwa agregacji –