码迷,mamicode.com
首页 > 其他好文 > 详细

(48)ElasticSearch之查询结果分析

时间:2020-04-07 20:51:31      阅读:68      评论:0      收藏:0      [点我收藏+]

标签:10个   数组   dex   准备   app   lin   pre   search   skipped   

  1、准备数据

PUT /lib
{
    "settings":{
        "number_of_shards":3,
        "number_of_replicas":0
      },
        "mappings":{
            "user":{
                "properties":{
                    "name":{"type":"text"},
                    "address":{"type":"text"},
                    "age":{"type":"integer"},
                    "interests":{"type":"text"},
                    "birthday":{"type":"date"}
                }
            }
        }
}
put /lib/user/1
{
    "name":"zhaoliu",
    "address":"hei long jiang sheng tie ling shi",
    "age":50,
    "birthday":"1970-12-12",
    "interests":"xi huang hejiu,duanlian,lvyou"
}

put /lib/user/2
{
    "name":"zhaoming",
    "address":"bei jing hai dian qu qing he zhen",
    "age":20,
    "birthday":"1998-10-12",
    "interests":"xi huan hejiu,duanlian,changge"
}

put /lib/user/3
{
    "name":"lisi",
    "address":"bei jing hai dian qu qing he zhen",
    "age":23,
    "birthday":"1998-10-12",
    "interests":"xi huan hejiu,duanlian,changge"
}

put /lib/user/4
{
    "name":"wangwu",
    "address":"bei jing hai dian qu qing he zhen",
    "age":26,
    "birthday":"1998-10-12",
    "interests":"xi huan biancheng,tingyinyue,lvyou"
}

put /lib/user/5
{
    "name":"zhangsan",
    "address":"bei jing chao yang qu",
    "age":29,
    "birthday":"1988-10-12",
    "interests":"xi huan tingyinyue,changge,tiaowu"
}

  2、操作演示

GET lib/user/_search
{
  "query": {"match": {
    "interests": "duanlian,changge"
  }}
}

  查询结果:

{
  "took": 6,
  "timed_out": false,
  "_shards": {
    "total": 3,
    "successful": 3,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": 4,
    "max_score": 1.4508328,
    "hits": [
      {
        "_index": "lib",
        "_type": "user",
        "_id": "2",
        "_score": 1.4508328,
        "_source": {
          "name": "zhaoming",
          "address": "bei jing hai dian qu qing he zhen",
          "age": 20,
          "birthday": "1998-10-12",
          "interests": "xi huan hejiu,duanlian,changge"
        }
      },
      {
        "_index": "lib",
        "_type": "user",
        "_id": "3",
        "_score": 0.87546873,
        "_source": {
          "name": "lisi",
          "address": "bei jing hai dian qu qing he zhen",
          "age": 23,
          "birthday": "1998-10-12",
          "interests": "xi huan hejiu,duanlian,changge"
        }
      },
      {
        "_index": "lib",
        "_type": "user",
        "_id": "5",
        "_score": 0.47000363,
        "_source": {
          "name": "zhangsan",
          "address": "bei jing chao yang qu",
          "age": 29,
          "birthday": "1988-10-12",
          "interests": "xi huan tingyinyue,changge,tiaowu"
        }
      },
      {
        "_index": "lib",
        "_type": "user",
        "_id": "1",
        "_score": 0.18232156,
        "_source": {
          "name": "zhaoliu",
          "address": "hei long jiang sheng tie ling shi",
          "age": 50,
          "birthday": "1970-12-12",
          "interests": "xi huang hejiu,duanlian,lvyou"
        }
      }
    ]
  }
}

  说明:

  took:本次查询耗费的时间,单位是毫秒。

  _shards:total,一共请求了3个分片;successful,请求成功的个数是3;failed,请求失败的个数没有。

  hits:total,这次查询 一共查询出多少个文档;max_score,在查询出的4个文档中,相关度最高的那个分数,hits,一个数组,包含所有查询出的文档,默认只查询出前10个。

  timed_out:设置超时时间,假如timeout=10ms,如果查询10ms内没有执行完,查出多少数据就会返回,不会让用户继续等待,es默认没有设置timed_out。

  示例:

GET /lib/user/_search?timeout=10ms{"_source":["address","name"],"query":{"match":{"interests":"changge"}}}

 

  

 

(48)ElasticSearch之查询结果分析

标签:10个   数组   dex   准备   app   lin   pre   search   skipped   

原文地址:https://www.cnblogs.com/javasl/p/12655334.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!