[英]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的公共字段,用于过滤不同类型的数据。
a.一种。 document_type = " user "
文档类型=“用户”
b.湾document_type = " user_detail "
文档类型=“用户详细信息”
{
"user_id" : "123",
"is_trial_active" : "true",
"updated_at" : "1577338950969",
"event_created_at" : "1577338950969",
"document_type" : "user"
}
{
"user_id" : "123",
"name" : "Shivam",
"gender" : "male",
"event_created_at" : 1575519449473,
"phone_number" : "+91-8383838383",
"document_type" : "user_detail",
"created_at" : 1576049770184
}
Note笔记
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_active在document_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.