Trực giác: Trong SQL cách nói:
Select distinct full_name from authors;
tương đương với
Select full_name from authors group by full_name;
Vì vậy, chúng ta có thể sử dụng nhóm/tổng hợp cú pháp trong ElasticSearch để tìm mục riêng biệt .
Giả sử sau đây là cấu trúc lưu trữ trong tìm kiếm đàn hồi:
[{
"author": "Brian Kernighan"
},
{
"author": "Charles Dickens"
}]
gì đã không làm việc: Plain hợp
{
"aggs": {
"full_name": {
"terms": {
"field": "author"
}
}
}
}
Tôi đã nhận lỗi sau:
{
"error": {
"root_cause": [
{
"reason": "Fielddata is disabled on text fields by default...",
"type": "illegal_argument_exception"
}
]
}
}
gì đã làm việc như một nét duyên dáng: Phụ thêm .keyword với lĩnh vực
{
"aggs": {
"full_name": {
"terms": {
"field": "author.keyword"
}
}
}
}
Và sản lượng mẫu có thể là:
{
"aggregations": {
"full_name": {
"buckets": [
{
"doc_count": 372,
"key": "Charles Dickens"
},
{
"doc_count": 283,
"key": "Brian Kernighan"
}
],
"doc_count": 1000
}
}
}
Mẹo thêm:
Chúng ta hãy giả định trường trong hàng đợi stion được lồng như sau:
[{
"authors": [{
"details": [{
"name": "Brian Kernighan"
}]
}]
},
{
"authors": [{
"details": [{
"name": "Charles Dickens"
}]
}]
}
]
Bây giờ truy vấn chính xác trở thành:
{
"aggregations": {
"full_name": {
"aggregations": {
"author_details": {
"terms": {
"field": "authors.details.name"
}
}
},
"nested": {
"path": "authors.details"
}
}
},
"size": 0
}
gì FULL_NAME nghĩa là gì? – neustart47
@ neustart47 full_name chỉ là tên của tập hợp –