【问题标题】:Correlating types in Elastic SearchElasticsearch 中的相关类型
【发布时间】: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 中编写查询来检索此信息?或者,如果无法在单个查询中实现这一点,我该如何执行以下步骤?

  1. 检索my-test-index中所有宠物的列表
  2. my-test-index/type中搜索每个宠物的类型

【问题讨论】:

    标签: json elasticsearch nosql


    【解决方案1】:

    如果您在所有者文档中包含该类型,这将是一个简单的术语聚合,其中包含一个过滤所有者的查询。您也可以考虑父/子,但如果解决方案是在您的文档中添加一个字段,我会尝试这样做并保持简单。

    【讨论】:

      猜你喜欢
      • 2017-06-08
      • 1970-01-01
      • 1970-01-01
      • 2016-12-29
      • 1970-01-01
      • 1970-01-01
      • 2013-01-28
      • 1970-01-01
      • 2019-10-18
      相关资源
      最近更新 更多