zoukankan      html  css  js  c++  java
  • 63.es中的type数据类型

    主要知识点

    • 理解es中的type数据类型

       

    一、type的理解

    type是一个index中用来区分类似的数据的,但是可能有不同的fields,而且有不同的属性来控制索引建立、分词器。fieldvalue值在底层的lucene中建立索引的时候,全部是opaque bytes类型,不区分类型的。lucene是没有type的概念的,在document中,实际上将type作为一个documentfield来存储,即_typees通过_type来进行type的过滤和筛选。一个index中的多个type,实际上是放在一起存储的,因此一个index下,不能有多个type重名但是类型或其他设置不同,因为那样是无法处理的。

       

    二、示例

    假设有如下一个index

       

    PUT /goods

    {

    "ecommerce": {

    "mappings": {

    "elactronic_goods": {

    "properties": {

    "name": {

    "type": "string",

    },

    "price": {

    "type": "double"

    },

    "service_period": {

    "type": "string"

    }                        

    }

    },

    "fresh_goods": {

    "properties": {

    "name": {

    "type": "string",

    },

    "price": {

    "type": "double"

    },

    "eat_period": {

    "type": "string"

    }

    }

    }

    }

    }

    }

    有如下两条数据

    {

    "name": "geli kongtiao",

    "price": 1999.0,

    "service_period": "one year"

    }

    {

    "name": "aozhou dalongxia",

    "price": 199.0,

    "eat_period": "one week"

    }

       

    在底层的存储是这样子的:

       

    {

    "ecommerce": {

    "mappings": {

    "_type": {

    "type": "string",

    "index": "not_analyzed"

    },

    "name": {

    "type": "string"

    }

    "price": {

    "type": "double"

    }

    "service_period": {

    "type": "string"

    }

    "eat_period": {

    "type": "string"

    }

    }

    }

    }

       

    {

    "_type": "elactronic_goods",

    "name": "geli kongtiao",

    "price": 1999.0,

    "service_period": "one year",

    "eat_period": ""

    }

       

    {

    "_type": "fresh_goods",

    "name": "aozhou dalongxia",

    "price": 199.0,

    "service_period": "",

    "eat_period": "one week"

    }

    可以看出,在es内部,会把所有field合并,对于一个type中没有的field就用空值替代。

    所以,在一个index下不同type的同名field的类型必须一致,不然就会冲突。

    最佳实践,将类似结构的type放在一个index下,这些type应该有多个field是相同的

    因此,如果将两个typefield完全不同,放在一个index下,那么就每条数据都至少有一半的field在底层的lucene中是空值,会有严重的性能问题。

  • 相关阅读:
    关于content-type请求头的说明
    RabbitMQ
    tornado
    flask总结之session,websocket,上下文管理
    爬虫相关问题总结
    爬虫之scrapy框架
    爬虫之Selenium模块
    爬虫之Beautifulsoup及xpath
    爬虫之requests
    SQLAlchemy
  • 原文地址:https://www.cnblogs.com/liuqianli/p/8475477.html
Copyright © 2011-2022 走看看