zoukankan      html  css  js  c++  java
  • ES索引的一些长度限制

    一个ES索引最大可以支持多少个shard?理论上无限扩展,我推测最大应该是java array的最大长度:Integer.MAX_VALUE。通常业务为了保证查询效率,往往会限制data node上shards的总个数(cluster.routing.allocation.total_shards_per_node)或者某个索引的shards个数(index.routing.allocation.total_shards_per_node)。

    一个ES shard(lucene index)最多可以索引2,147,483,519个document。https://issues.apache.org/jira/browse/LUCENE-5843

    一个ES mapping默认最多可以有1000个字段(index.mapping.total_fields.limit),因为ES DSL默认最多支持1000个search条件表达式(rewrite之后)。nest对象默认最多50个字段(index.mapping.nested_fields.limit),另外最多支持10000个nest对象(index.mapping.nested_objects.limit)。

    一个ES keyword字段支持的最大keyword长度是32766个byte(这个是hard code的为ByteBlockPool的BYTE_BLOCK_SIZE-2),如果keyword字段存的是ES的Array, 则变为Array中的每term最大32766个byte,Array的最大size不受约束,但Array最大存储量是所有keyword总和为2147483647,可参考Lucene8.0.0的BytesRefHash的类注释。

    这就引出来一个有趣的问题,ES type=keyword的字段存Array和单个keyword的区别在哪里?

    ES本身并不做底层的索引和存储,lucene承担了这部分工作,通过lucene构造一个带有Array字段的document如下:

    public static void indexDocument(IndexWriter writer) throws IOException {
    List<String> cityNameList = new ArrayList();
    cityNameList.add("BeiJing");
    cityNameList.add("ShangHai");
    cityNameList.add("HangZhou");

    Document doc = new Document();
    for(int i = 0; i<cityNameList.size();i++) {
    doc.add(new StringField("cityName", new BytesRef(cityNameList.get(i)), Field.Store.YES));
    }
    long writerResult = writer.addDocument(doc);
    System.out.println(writerResult);
    }

    可以看到一个document创建多个StringField,每个StringField都采用同样的fieldname: cityName。通过debug addDocument方法,看到lucene会for循环所有的StringField并根据fieldName进行索引,相同fieldName会归为同一个PerField处理,最终每个BytesRef都会都会存到同一个BytesRefHash结构中,从而完成了数组(其实存的HashMap)的存储。同时不难推断,针对Array的term query耗时应该是寻址Hash碰撞链与Hash碰撞链上遍历到具体内容的时间之和,寻址hash链是O(1),hash链遍历是O(n),n是hash碰撞链的长度。这个长度又跟hash取模和Array size有关,lucene8.0.0默认的hash模是15,terms个数来自索引数据,Array size越大查询越耗时,好在不是线性增长而是log15n,size非常大时term query耗时并不会增长很多。

    Reference:

    https://www.amazingkoala.com.cn/Lucene/gongjulei/2019/0218/32.html

  • 相关阅读:
    hdu 3790 最短路径问题
    hdu 2112 HDU Today
    最短路问题 以hdu1874为例
    hdu 1690 Bus System Floyd
    hdu 2066 一个人的旅行
    hdu 2680 Choose the best route
    hdu 1596 find the safest road
    hdu 1869 六度分离
    hdu 3339 In Action
    序列化和反序列化
  • 原文地址:https://www.cnblogs.com/zhq1007/p/12349075.html
Copyright © 2011-2022 走看看