我正在尝试在运行“条款”ElasticSearch查询(或任何其他查询)时获取_source字段中的所有子字段而不是文档。
假设我有类别的文档和许多其他数据,如颜色,大小,重量......这些字段是动态的,我不知道哪些字段会存在。
文件示例:
{
"_index": "myindex",
"_type": "document",
"_id": "1",
"_score": 1,
"_source": {
"entity_id": "1",
"is_in_stock": "1",
"weight": null,
"color": null,
"name": "My Document",
"description": "Hello World",
"categories": [
"4185",
"4626"
]
}
}
某些文档有颜色,但不是全部,因此可以获取特定查询的所有非空字段,如下所示:
{
"query": {
"terms" : { "categories" : ["5581"] }
}
}
预期结果会是这样的(假设提供的文档是我索引中唯一的文档):
{
"took": 42,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 0,
"hits": []
},
"aggregations": {
"category_att": {
"doc_count": 1,
"cosmetique": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "entity_id",
"doc_count": 1
},
{
"key": "is_in_stock",
"doc_count": 1
},
{
"key": "name",
"doc_count": 1
},
{
"key": "description",
"doc_count": 1
},
{
"key": "categories",
"doc_count": 1
}
]
}
}
}
}
谢谢!