【发布时间】:2021-07-24 04:54:39
【问题描述】:
我能够在弹性搜索 6.8 中使用聚合查询获取数据库中文本字段的所有值:
{
aggs: {
values: {
terms: { field: 'City.keyword', size: 200 },
},
},
size: 0,
};
我正在尝试对嵌套字段做同样的事情。
以下是文本字段(城市)和嵌套字段(冷却)的示例
"City": "Fredericksburg",
"Cooling": [
{
"key": "Fuel",
"value": "Electric"
},
{
"key": "Central Air",
"value": "Y"
},
{
"key": "Central A/C",
"value": "true"
}
],
这是我一直在参考的文档: https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-bucket-terms-aggregation.html
以下是相关映射:
{
"listings:366": {
"mappings": {
"_default_": {
"_all": {
"enabled": false
},
"dynamic_templates": [
...
{
"Cooling": {
"path_match": "Cooling.*",
"mapping": {
"type": "text"
}
}
},
...
],
"properties": {
...
"Cooling": {
"type": "nested"
},
...
}
},
"listings": {
"_all": {
"enabled": false
},
"dynamic_templates": [
...
{
"Cooling": {
"path_match": "Cooling.*",
"mapping": {
"type": "text"
}
}
},
...
],
"properties": {
...
"Cooling": {
"type": "nested",
"properties": {
"key": {
"type": "text"
},
"value": {
"type": "text"
}
}
},
}
}
}
}
}
【问题讨论】:
标签: elasticsearch