【发布时间】:2018-02-01 07:00:51
【问题描述】:
我有以下 Elastic Search 索引,my-test-index,文档按以下类型分组:
所有者
{
"_index": "my-test-index",
"_type": "owner",
"_id": "AV4GXRQmXr6DxJJbKJTy",
"_source": {
"owner": "Jane",
"pet": "cat",
"city": "NYC"
}
},
{
"_index": "my-test-index",
"_type": "owner",
"_id": "AV4GXRQmXr6DxJJbKJT0",
"_source": {
"owner": "Jason",
"pet": "snake",
"city": "Boston"
}
},
{
"_index": "my-test-index",
"_type": "owner",
"_id": "AV4GXRQmXr6DxJJbKJTz",
"_source": {
"owner": "Jack",
"pet": "dog",
"city": "NYC"
}
},
和类型:
{
"_index": "my-test-index",
"_type": "type",
"_id": "AV4GXXuyXr6DxJJbKJUU",
"_source": {
"pet": "snake",
"type": "reptile"
}
},
{
"_index": "my-test-index",
"_type": "type",
"_id": "AV4GXXuyXr6DxJJbKJUT",
"_source": {
"pet": "dog",
"type": "mammal"
}
},
{
"_index": "my-test-index",
"_type": "type",
"_id": "AV4GXXuyXr6DxJJbKJUS",
"_source": {
"pet": "cat",
"type": "mammal"
}
},
{
"_index": "my-test-index",
"_type": "type",
"_id": "AV4GXXuyXr6DxJJbKJUW",
"_source": {
"pet": "penguin",
"type": "bird"
}
},
{
"_index": "my-test-index",
"_type": "type",
"_id": "AV4GXXuyXr6DxJJbKJUV",
"_source": {
"pet": "parrot",
"type": "bird"
}
}
我想了解每位主人的宠物类型。例如,简有一只哺乳动物,因为她的猫属于“哺乳动物”类型。如何在 Elastic Search 中编写查询来检索此信息?或者,如果无法在单个查询中实现这一点,我该如何执行以下步骤?
- 检索
my-test-index中所有宠物的列表 - 在
my-test-index/type中搜索每个宠物的类型
【问题讨论】:
标签: json elasticsearch nosql