• ElasticSearch search timeout机制+_multi-index&multi-type搜索模式+分页搜索以及deep paging


    一.search timeout机制 

    对于一次search


    GET /_search

    {
    "took": 6,
    "timed_out": false,
    "_shards": {
    "total": 6,
    "successful": 6,
    "failed": 0
    },
    "hits": {
    "total": 10,
    "max_score": 1,
    "hits": [
    {
    "_index": ".kibana",
    "_type": "config",
    "_id": "5.2.0",
    "_score": 1,
    "_source": {
    "buildNum": 14695
    }}}}}


    took:整个搜索请求花费了多少毫秒

    hits.total:本次搜索,返回了几条结果
    hits.max_score:本次搜索的所有结果中,最大的相关度分数是多少,每一条document对于search的相关度,越相关,_score分数越大,排位越靠前
    hits.hits:默认查询前10条数据,完整数据,_score降序排序

    shards:shards fail的条件(primary和replica全部挂掉),不影响其他shard。默认情况下来说,一个搜索请求,会打到一个index的所有primary shard上去,当然了,每个primary shard都可能会有一个或多个replic shard,所以请求也可以到primary shard的其中一个replica shard上去。

    timeout:默认无timeout,latency平衡completeness,手动指定timeout,timeout查询执行机制

    timeout=10ms,timeout=1s,timeout=1m
    GET /_search?timeout=10m

    二._multi-index&multi-type搜索模式解析以及搜索原理

    1、multi-index和multi-type搜索模式

    告诉你如何一次性搜索多个index和多个type下的数据

    /_search:所有索引,所有type下的所有数据都搜索出来
    /index1/_search:指定一个index,搜索其下所有type的数据
    /index1,index2/_search:同时搜索两个index下的数据
    /*1,*2/_search:按照通配符去匹配多个索引
    /index1/type1/_search:搜索一个index下指定的type的数据
    /index1/type1,type2/_search:可以搜索一个index下多个type的数据
    /index1,index2/type1,type2/_search搜索多个index下的多个type的数据
    /_all/type1,type2/_search:_all,可以代表搜索所有index下的指定type的数据

    2、初步图解一下简单的搜索原理

    搜索原理初步图解

     三.分页搜索以及deep paging性能问题

    1、讲解如何使用es进行分页搜索的语法

    size,from

    GET /_search?size=10
    GET /_search?size=10&from=0
    GET /_search?size=10&from=20

    分页的上机实验

    GET /test_index/test_type/_search

    "hits": {
    "total": 9,
    "max_score": 1,

    我们假设将这9条数据分成3页,每一页是3条数据,来实验一下这个分页搜索的效果


    GET /test_index/test_type/_search?from=0&size=3


    {
    "took": 2,
    "timed_out": false,
    "_shards": {
    "total": 5,
    "successful": 5,
    "failed": 0
    },
    "hits": {
    "total": 9,
    "max_score": 1,
    "hits": [
    {
    "_index": "test_index",
    "_type": "test_type",
    "_id": "8",
    "_score": 1,
    "_source": {
    "test_field": "test client 2"
    }
    },
    {
    "_index": "test_index",
    "_type": "test_type",
    "_id": "6",
    "_score": 1,
    "_source": {
    "test_field": "tes test"
    }
    },
    {
    "_index": "test_index",
    "_type": "test_type",
    "_id": "4",
    "_score": 1,
    "_source": {
    "test_field": "test4"
    }
    }
    ]
    }
    }

    第一页:id=8,6,4

    GET /test_index/test_type/_search?from=3&size=3

    第二页:id=2,自动生成,7

    GET /test_index/test_type/_search?from=6&size=3

    第三页:id=1,11,3

    2、什么是deep paging问题?为什么会产生这个问题,它的底层原理是什么?

    deep paging性能问题,以及原理深度图解揭秘,很高级的知识点

     

     

     

     

  • 相关阅读:
    各种版本控制器的作用
    mybatis的一些特殊符号标识(大于,小于,等于,不等于)
    struts2的作用是什么
    js中给数组添加元素的方法有哪些
    springmvc中拦截器配置格式
    js中require()的用法----JS如何连接数据库执行sql语句或者建立数据库连接池
    hover()函数的用法
    error和exception的不同与相同
    cookie和session的区别有哪些
    数据库连接池的工作机制是什么
  • 原文地址:https://www.cnblogs.com/Transkai/p/11276351.html
Copyright © 2020-2023  润新知