ES 深度分页

三种方式

  1. from + size

  2. scroll

  3. search_after

三者对比,各自的优缺点、适用场景

实验(es version 7.7)

  1. 创建类型mapping
PUT /studentv1
{
  "mappings" : {
    "doc" : {
      "properties" : {
        "name" :  {"type" :  "text"},
         "classs" : {"type" :  "text"},
         "age" :  {"type" :  "integer"}
      }
    }
  }
}

报错

{
  "error" : {
    "root_cause" : [
      {
        "type" : "mapper_parsing_exception",
        "reason" : "Root mapping definition has unsupported parameters:  [doc : {properties={classs={type=string}, name={type=text}, age={type=integer}}}]"
      }
    ],
    "type" : "mapper_parsing_exception",
    "reason" : "Failed to parse mapping [_doc]: Root mapping definition has unsupported parameters:  [doc : {properties={classs={type=string}, name={type=text}, age={type=integer}}}]",
    "caused_by" : {
      "type" : "mapper_parsing_exception",
      "reason" : "Root mapping definition has unsupported parameters:  [doc : {properties={classs={type=string}, name={type=text}, age={type=integer}}}]"
    }
  },
  "status" : 400
}

出现这个的原因是,elasticsearch7默认不在支持指定索引类型,默认索引类型是_doc,如果想改变,则配置include_type_name: true 即可(这个没有测试,官方文档说的,无论是否可行,建议不要这么做,因为elasticsearch8后就不在提供该字段)。
调整为

DELETE  /studentv1
PUT /studentv1
{
  "mappings" : {
      "properties" : {
        "name" :  {"type" :  "text"},
          "age" :  {"type" :  "integer"},
         "class" : {"type" :  "text"}
       
      }
  }

DELETE  /studentv2
PUT /studentv2
{
  "mappings" : {
      "properties" : {
         "uid" :  {"type" :  "integer"},
        "name" :  {"type" :  "text"},
          "age" :  {"type" :  "integer"},
         "class" : {"type" :  "text"}
       
      }
  }
}
POST /studentv1/_doc
{
  "name":"ls",
  "age": 28,
  "class":"1-1"
}

GET /studentv1/_doc/zl7wBnkBSSB4rsMqoiB-

GET /studentv1/_search
{
  "query":{
    "match_all": {}
  }
}

POST /studentv2/_doc
{
  "uid": 10000,
  "name":"ls",
  "age": 28,
  "class":"1-1"
}

GET /studentv2/_doc/CF7yBnkBSSB4rsMq-CFn

GET /studentv2/_search
{
  "query":{
    "match_all": {}
  }
}

参考

  1. https://www.cnblogs.com/hello-shf/p/11543453.html
posted @ 2021-04-29 15:23  zendwang  阅读(135)  评论(0编辑  收藏  举报