代码之家  ›  专栏  ›  技术社区  ›  Panagiotis Simakis Maksym Potapchuk

ElasticSearch:单个索引中的多个类型

  •  0
  • Panagiotis Simakis Maksym Potapchuk  · 技术社区  · 6 年前

    我试图在一个索引中创建多个类型。例如,我尝试创建两种类型( host ,请 post )在 ytb 索引以便在它们之间创建父子关系。

    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"
                  }
              }
          }
      }
    }
    

    但我得到了这个错误:

    {
      "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
    }
    

    更新: ElasticSearch版本:6.3.0

    1 回复  |  直到 6 年前
        1
  •  7
  •   Val    6 年前

    如果您有ES 5.6或更高版本,您需要阅读此内容。总而言之,映射类型将被删除,从ES 6开始,每个索引只有一个类型将成为标准。

    为了在评论中回答您的问题,我知道另一个类似于kibana的工具(实际上是kibana fork),它知道如何处理连接和关系数据。它被称为 Kibi 通过警报器解决方案。同时阅读 blog announcement .