简体   繁体   English

弹性搜索/kibana 从同一索引的 2 个文档中获取数据?

[英]Elastic search/kibana get data from 2 documents of same Index?

I have 1 index in elastic search data-production for storing documents.我在用于存储文档的弹性搜索数据生产中有 1 个索引。 This index has a common field in each document named: document_type to filter the different type of data.这个索引在每个文档中都有一个名为: document_type的公共字段,用于过滤不同类型的数据。

I have 2 types of documents in the index: data-production我在索引中有两种类型的文档:数据生产

a.一种。 document_type = " user "文档类型=“用户

b.document_type = " user_detail "文档类型=“用户详细信息

Example Data示例数据

  1. Users用户
        {
          "user_id" : "123",
          "is_trial_active" : "true",
          "updated_at" : "1577338950969",
          "event_created_at" : "1577338950969",
          "document_type" : "user"
        }
  1. Detail of User用户详情
    {         
       "user_id" : "123",
       "name" : "Shivam",
       "gender" : "male",
       "event_created_at" : 1575519449473,
       "phone_number" : "+91-8383838383",
       "document_type" : "user_detail",
       "created_at" : 1576049770184
    }

Note笔记

  1. user_id is the common key in both document_type user_id 是两个document_type 中的公共键
  2. Using elasticsearch 7.3.1 version使用elasticsearch 7.3.1 版本

Question

How to fetch detail of users from document_type ="user_details" whose is_trial_active is not true in document_type ="user"?如何从document_type ="user_details" 中获取用户的详细信息,其is_trial_activedocument_type ="user" 中不正确?

A working example:一个工作示例:

Mappings映射

PUT my_index
{
  "mappings": {
    "properties": {
      "document_type": {
        "type": "join",
        "relations": {
          "user": "user_detail"
        }
      }
    }
  }
}

Post few documents发布一些文件

PUT my_index/_doc/1
{
  "user_id": "123",
  "is_trial_active": "false", ---> note i changed this to false for the example
  "updated_at": "1577338950969",
  "event_created_at": "1577338950969",
  "document_type": "user"
}

PUT my_index/_doc/2?routing=1
{
  "user_id": "123",
  "name": "Shivam",
  "gender": "male",
  "event_created_at": 1575519449473,
  "phone_number": "+91-8383838383",
  "created_at": 1576049770184,
  "document_type": {
    "name": "user_detail",
    "parent": "1"  --> you can insert array of parents
  }
}

Search Query搜索查询

GET my_index/_search
{
  "query": {
    "has_parent": {
      "parent_type": "user",
      "query": {
        "bool": {
          "must_not": [
            {
              "term": {
                "is_trial_active": {
                  "value": "true"
                }
              }
            }
          ]
        }
      }
    }
  }
}

Results结果

"hits" : [
  {
    "_index" : "my_index",
    "_type" : "_doc",
    "_id" : "2",
    "_score" : 1.0,
    "_routing" : "1",
    "_source" : {
      "user_id" : "123",
      "name" : "Shivam",
      "gender" : "male",
      "event_created_at" : 1575519449473,
      "phone_number" : "+91-8383838383",
      "created_at" : 1576049770184,
      "document_type" : {
        "name" : "user_detail",
        "parent" : "1"
      }
    }
  }
]

Hope this helps希望这可以帮助

you can use has_parent query to retrieve child document您可以使用has_parent查询来检索子文档

Hope the following query work for you希望以下查询对您有用

GET data-production/_search
{
  "query": {
    "has_parent": {
      "parent_type": "user",
      "query": {
        "bool": {
          "must_not": [
            {
              "term": {
                "is_trial_active": {
                  "value": "true"
                }
              }
            }
          ]
        }
      }
    }
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 是否在kibana中删除索引,在弹性搜索中也删除相同的索引? - Does deleting index in kibana, deletes same index in elastic search too? 从弹性搜索 kibana 中获取文档总数以及过滤后的文档数 - Get total number of documents along with filtered document count from elastic search kibana 是否可以在不使用 Logstash 或 FileBeats 或 Kibana 的情况下将数据索引到 Elastic Search 中? - Is is possible to index data into Elastic Search without using Logstash or FileBeats or Kibana? 在弹性搜索中将多个文档输入到相同的索引 - Enter multiple documents to same the same index in elastic search 带有数字的Kibana搜索未从弹性搜索中获取数据 - Kibana search with numbers is not fetching data from elastic search 如何在弹性搜索中从多个索引中获取数据 - How to get the data from multiple index in elastic search 弹性搜索-如何检查kibana中是否使用了索引 - Elastic search - how to check if index is used in kibana 如何将弹性搜索查询从Kibana 3转换为Kibana 4 - How to convert elastic search queries from Kibana 3 to Kibana 4 如何通过使用日期作为弹性搜索的字符串比较来获取文档? - How to get documents by using date as the string comparison from elastic search? 使用弹性搜索索引迷你文档 - Index minio Documents Using Elastic-Search
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM