简体   繁体   English

elasticsearch:单个索引中的多种类型

[英]elasticsearch: multiple types in a single index

I'm trying to create multiple types in a single index. 我正在尝试在单个索引中创建多个类型。 For example I'm trying to create two types ( host , post ) in ytb index in order to create parent-child relationship between of them. 例如,我试图在ytb索引中创建两种类型( hostpost ),以便在它们之间创建父子关系。

PUT /ytb
{
  "mappings": {
      "post": {
          "_parent": {
              "type": "host" 
            },
          "properties":{
            "@timestamp": {
                  "type": "date"
              },
            "indexed": {
                  "type": "date"
              },
              "n_comments": {
                  "type": "long"
              }, 
              "n_harvested": {
                  "type": "long"
              }, 
              "n_likes": {
                  "type": "long"
              },
              "network": {
                  "fields": {
                      "keyword": {
                          "ignore_above": 256, 
                          "type": "keyword"
                      }
                  }, 
                  "type": "text"
              },
              "parent_id": {
                  "fields": {
                      "keyword": {
                          "ignore_above": 256, 
                          "type": "keyword"
                      }
                  }, 
                  "type": "text"
              }, 
              "post_dbid": {
                  "type": "long"
              }, 
              "post_id": {
                  "fields": {
                      "keyword": {
                          "ignore_above": 256, 
                          "type": "keyword"
                      }
                  }, 
                  "type": "text"
              }, 
              "post_netid": {
                  "fields": {
                      "keyword": {
                          "ignore_above": 256, 
                          "type": "keyword"
                      }
                  }, 
                  "type": "text"
              }, 
              "published": {
                  "type": "date"
              }
          }
      },
      "host": {
          "properties": {
              "@timestamp": {
                  "type": "date"
              }, 
              "@version": {
                  "fields": {
                      "keyword": {
                          "ignore_above": 256, 
                          "type": "keyword"
                      }
                  }, 
                  "type": "text"
              }, 
              "country": {
                  "fields": {
                      "keyword": {
                          "ignore_above": 256, 
                          "type": "keyword"
                      }
                  }, 
                  "type": "text"
              }, 
              "host_dbid": {
                  "type": "long"
              }, 
              "host_id": {
                  "fields": {
                      "keyword": {
                          "ignore_above": 256, 
                          "type": "keyword"
                      }
                  }, 
                  "type": "text"
              }, 
              "host_netid": {
                  "fields": {
                      "keyword": {
                          "ignore_above": 256, 
                          "type": "keyword"
                      }
                  }, 
                  "type": "text"
              }, 
              "id": {
                  "fields": {
                      "keyword": {
                          "ignore_above": 256, 
                          "type": "keyword"
                      }
                  }, 
                  "type": "text"
              }, 
              "indexed": {
                  "type": "date"
              }, 
              "language": {
                  "fields": {
                      "keyword": {
                          "ignore_above": 256, 
                          "type": "keyword"
                      }
                  }, 
                  "type": "text"
              },
              "name": {
                  "fields": {
                      "keyword": {
                          "ignore_above": 256, 
                          "type": "keyword"
                      }
                  }, 
                  "type": "text"
              }, 
              "vertical": {
                  "fields": {
                      "keyword": {
                          "ignore_above": 256, 
                          "type": "keyword"
                      }
                  }, 
                  "type": "text"
              }
          }
      }
  }
}

but I'm getting this error: 但我收到此错误:

{
  "error": {
    "root_cause": [
      {
        "type": "illegal_argument_exception",
        "reason": "Rejecting mapping update to [ytb] as the final mapping would have more than 1 type: [post, host]"
      }
    ],
    "type": "illegal_argument_exception",
    "reason": "Rejecting mapping update to [ytb] as the final mapping would have more than 1 type: [post, host]"
  },
  "status": 400
}

UPDATE: Elasticsearch version: 6.3.0 更新: Elasticsearch版本:6.3.0

If you have ES 5.6 or more recent, you need to read this. 如果您使用的是ES 5.6或更高版本,则需要阅读。 To sum it up, mapping types are going to be removed and only one type per index is going to be the norm as of ES 6 onwards. 概括起来,从ES 6开始,将删除映射类型,并且每个索引仅一种类型将成为标准。

To answer your question in the comment, I know of another Kibana-like tool (a Kibana fork actually) that knows how to handle JOINs and relational data. 为了在评论中回答您的问题,我知道另一个类似Kibana的工具(实际上是Kibana叉子),它知道如何处理JOIN和关系数据。 It is called Kibi by Siren Solutions. 它被Siren Solutions称为Kibi Also read the blog announcement . 另请阅读博客公告

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM