【问题标题】:Elastic search - Retrieve data from multiple types弹性搜索 - 从多种类型中检索数据
【发布时间】:2018-08-15 11:01:01
【问题描述】:

我正在使用 elasticsearch,我有两种类型来保存我的数据。

现在我需要使用单个查询从这两种类型中检索数据。

请看我的用例

我有两种类型,称为基本和标记,我保存文档如下

myindex/basic

{ "id": "100", "name": "汤姆" }

myindex/basic

{ "id": "101", "name": "约翰"

}

myindex/marks

{ "id": "100", "mark": "300"

}

myindex/marks

{ "id": "101", "mark": "500" }

现在我需要获取一个学生的姓名和标记,他的 id 是 100。

有没有可能得到这样的结果。

我开始知道这种类型的数据模型对 nosql 不利,但在这里我需要它,因为这些记录是从 RDBMS DB 复制的。

如有任何建议,请提前致谢。

【问题讨论】:

标签: elasticsearch elassandra


【解决方案1】:

您可以通过在 url 中列出它们来在单个查询中查询这两种类型

POST myindex/basic,marks/_search

您也可以通过 id 过滤所有这些

POST myindex/basic,marks/_search
{
  "query": {
    "bool": {
      "must": [
        {"term": {
          "id": {
            "value": 100
          }
        }}
      ]
    }
  }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-17
    • 2023-04-03
    • 1970-01-01
    • 1970-01-01
    • 2014-10-23
    • 2019-01-08
    相关资源
    最近更新 更多