ElasticSearch22:初识搜索引擎_search结果深入解析,timeout揭秘

1.我们如果发送一个搜索请求,会得到一个搜索结果

执行一条简单的搜索GET /_search

{
  "took": 26,  
  "timed_out": false,
  "_shards": { 
    "total": 11,
    "successful": 11,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": 21,
    "max_score": 1,
    "hits": [
      {
        "_index": ".kibana",
        "_type": "doc",
        "_id": "config:6.1.1",
        "_score": 1,
        "_source": {
          "type": "config",
          "updated_at": "2017-12-25T08:15:46.917Z",
          "config": {
            "buildNum": 16350,
            "defaultIndex": "cdf712f0-e94b-11e7-a430-13b2f048e43f"
          }
        }
      }

}

}


took:表示请求花费的时间,单位ms

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

hits.total  本次搜索,返回几条搜索结果

hits.max_score:本次搜索的所有结果中,最大的相关度分数是多少,每一条document对于search对于search的相关度,越相关_score分数越大,排名越靠前。

hits.hits :默认情况下,只查询出前面的10条数据。完整数据,_score按倒叙排序,max_source

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


 2. 为什么默认没有timeout?timeout查询指定机制

      比如说,你的搜索特别慢,每个shard都要花费好几分钟才能查询出来所有的数据,那么你的搜索请求也会等待好几分钟之后才会返回

      我们有些搜索应用,对时间是很敏感的,比如说电商网站,也不会说让用户等10分钟,才能等到一次搜索请求的结果,如果那样,用户基本都没了。

      timeout机制,指定每个shard就只能在timeout的时间范围内,将搜索到的部分数据(也可能是全部数据),直接立即返回给client程序,而不是等到所有的数据全部搜索出来以后再返回。

      确保说,一次搜索请求可以在用户指定的timeout时长内完成,为一些时间敏感的搜索应用提供良好的支持。

     可以指定timeout时长,需要带上单位



例子:

GET /_search?timeout=1ms


执行结果:

{
  "took": 11,
  "timed_out": false,
  "_shards": {
    "total": 11,
    "successful": 11,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": 21,
    "max_score": 1,
    "hits": [
      {
        "_index": ".kibana",
        "_type": "doc",
        "_id": "config:6.1.1",
        "_score": 1,
        "_source": {
          "type": "config",
          "updated_at": "2017-12-25T08:15:46.917Z",
          "config": {
            "buildNum": 16350,
            "defaultIndex": "cdf712f0-e94b-11e7-a430-13b2f048e43f"
          }
        }
      },
      {
        "_index": ".kibana",
        "_type": "doc",
        "_id": "index-pattern:cdf712f0-e94b-11e7-a430-13b2f048e43f",
        "_score": 1,
        "_source": {
          "type": "index-pattern",
          "updated_at": "2017-12-27T02:05:13.335Z",
          "index-pattern": {
            "title": "ecommerce",
            "fields": """[{"name":"_id","type":"string","count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":false},{"name":"_index","type":"string","count":4,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":false},{"name":"_score","type":"number","count":0,"scripted":false,"searchable":false,"aggregatable":false,"readFromDocValues":false},{"name":"_source","type":"_source","count":0,"scripted":false,"searchable":false,"aggregatable":false,"readFromDocValues":false},{"name":"_type","type":"string","count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":false},{"name":"desc","type":"string","count":0,"scripted":false,"searchable":true,"aggregatable":false,"readFromDocValues":false},{"name":"desc.keyword","type":"string","count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":true},{"name":"name","type":"string","count":0,"scripted":false,"searchable":true,"aggregatable":false,"readFromDocValues":false},{"name":"name.keyword","type":"string","count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":true},{"name":"price","type":"number","count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":true},{"name":"producer","type":"string","count":0,"scripted":false,"searchable":true,"aggregatable":false,"readFromDocValues":false},{"name":"producer.keyword","type":"string","count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":true},{"name":"tags","type":"string","count":0,"scripted":false,"searchable":true,"aggregatable":false,"readFromDocValues":false},{"name":"tags.keyword","type":"string","count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":true}]"""
          }
        }
      },
      {
        "_index": "ecommerce",
        "_type": "product",
        "_id": "5",
        "_score": 1,
        "_source": {
          "name": "zhuyan yagao",
          "desc": "meibai jiankang",
          "price": 54,
          "producer": "zhuyan producer",
          "tags": [
            "fangzhu",
            "meibai",
            "jiankang"
          ]
        }
      },
      {
        "_index": "test_index",
        "_type": "test_type",
        "_id": "10",
        "_score": 1,
        "_source": {
          "test_field": "test_201712291052",
          "test_field2": "test002"
        }
      },
      {
        "_index": "test_index",
        "_type": "test_type",
        "_id": "QIBLoGABN5gu7um0xJGZ",
        "_score": 1,
        "_source": {
          "ids": [
            1,
            2
          ]
        }
      },
      {
        "_index": "test_index",
        "_type": "test_type",
        "_id": "8",
        "_score": 1,
        "_source": {
          "test_field": "xxx81",
          "test_field2": "xxx00000000"
        }
      },
      {
        "_index": "ecommerce",
        "_type": "product",
        "_id": "4",
        "_score": 1,
        "_source": {
          "name": "yayale yagao",
          "desc": "gaoxiao meibai",
          "price": 100,
          "producer": "yayale producer",
          "tags": [
            "fangzhu",
            "meibai",
            "qingxin"
          ]
        }
      },
      {
        "_index": "ecommerce",
        "_type": "product",
        "_id": "1131mmABEP2XuYqpoflk",
        "_score": 1,
        "_source": {
          "name": "heiren yagao",
          "desc": "gaoxiao meibai",
          "price": 100,
          "producer": "heiren producer",
          "tags": [
            "fangzhu",
            "meibai",
            "qingxin"
          ]
        }
      },
      {
        "_index": "ecommerce",
        "_type": "product",
        "_id": "2",
        "_score": 1,
        "_source": {
          "query": {
            "match": {
              "name": "yao"
            }
          }
        }
      },
      {
        "_index": "test_index",
        "_type": "test_type",
        "_id": "2",
        "_score": 1,
        "_source": {
          "test_field": "xxxxx000"
        }
      }
    ]
  }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值