(48)ElasticSearch之查詢結果分析


  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"}}}

 

  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM