![](/img/trans.png)
[英]Does deleting index in kibana, deletes same index in elastic search too?
[英]Elastic search/kibana get data from 2 documents of same Index?
我在用於存儲文檔的彈性搜索數據生產中有 1 個索引。 這個索引在每個文檔中都有一個名為: document_type的公共字段,用於過濾不同類型的數據。
一種。 文檔類型=“用戶”
灣文檔類型=“用戶詳細信息”
{
"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
}
筆記
如何從document_type ="user_details" 中獲取用戶的詳細信息,其is_trial_active在document_type ="user" 中不正確?
一個工作示例:
映射
PUT my_index
{
"mappings": {
"properties": {
"document_type": {
"type": "join",
"relations": {
"user": "user_detail"
}
}
}
}
}
發布一些文件
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
}
}
搜索查詢
GET my_index/_search
{
"query": {
"has_parent": {
"parent_type": "user",
"query": {
"bool": {
"must_not": [
{
"term": {
"is_trial_active": {
"value": "true"
}
}
}
]
}
}
}
}
}
結果
"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"
}
}
}
]
希望這可以幫助
您可以使用has_parent
查詢來檢索子文檔
希望以下查詢對您有用
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.