ES的语法学习

 ES打分介绍

确定文档和查询有多么相关的过程被称为打分(scoring):将查询作为输入,使用不同的手段来确定每一篇文档的得分,将每一个因素最后通过公式综合起来,返回该文档的最终得分。这个综合考量的过程,就是我们希望相关的文档被优先返回的考量过程。在Lucenees中这种相关性称为得分

文档打分的运作机制:TF-IDF

我们称之为TF-IDFTF是词频(term frequency),而IDF是逆文档频率(inverse document frequency)

 

 🌰:

es查相似车源:相同modelcode和citycode下的3个条件:需要:1、小于入参mile+偏移量2、晚于入参日期-偏移量3、小于入参price

POST ienterprise_jiaxuan_market_price/_search
{
  "from": 0,
  "size": 50,
  "query": {
    "bool": {
      "filter": [
        {
          "term": {
            "model_code": "13835-n"
          }
        },
        {
          "term": {
            "location": "南京"
          }
        },
        {
          "range": {
            "mileage": {
              "lte": "19"
            }
          }
        },{
          "range": {
            "price": {
              "lte": "18"
            }
          }
        },
        {
          "range": {
            "license_plate_date": {
              "gte": "2017-09"
            }
          }
        }
      ]
    }
  }
}
View Code

结果:

{
    "took":3,
    "timed_out":false,
    "_shards":{
        "total":5,
        "successful":5,
        "failed":0
    },
    "hits":{
        "total":5,
        "max_score":0,
        "hits":[
            {
                "_index":"ienterprise_jiaxuan_market_price_1573504339051",
                "_type":"default",
                "_id":"0beaad95-7a8e-4bfc-b570-bb6d5817acaa",
                "_score":0,
                "_source":{
                    "series_name":"凯迪拉克ATS-L",
                    "brand_name":"凯迪拉克",
                    "location_city_code":"00859",
                    "price":"18.00",
                    "site":"che168",
                    "publish_date":null,
                    "mileage":"2",
                    "model_name":"凯迪拉克ATS-L 2017款 28T 时尚型",
                    "model_code":"13835-n",
                    "location":"南京",
                    "financial_special_price":null,
                    "id":"0beaad95-7a8e-4bfc-b570-bb6d5817acaa",
                    "license_plate_city":"南京",
                    "color":"白色",
                    "license_plate_date":"2018-05",
                    "url":"https://www.che168.com/dealer/230650/35115685.html?pvareaid=100519&userpid=320000&usercid=320100"
                }
            },
            {
                "_index":"ienterprise_jiaxuan_market_price_1573504339051",
                "_type":"default",
                "_id":"c8d04533-d2fe-4ff7-9292-28f6c50af940",
                "_score":0,
                "_source":{
                    "series_name":"凯迪拉克ATS-L",
                    "brand_name":"凯迪拉克",
                    "location_city_code":"00859",
                    "price":"17.98",
                    "site":"che168",
                    "publish_date":null,
                    "mileage":"6",
                    "model_name":"凯迪拉克ATS-L 2017款 28T 时尚型",
                    "model_code":"13835-n",
                    "location":"南京",
                    "financial_special_price":null,
                    "id":"c8d04533-d2fe-4ff7-9292-28f6c50af940",
                    "license_plate_city":"南京",
                    "color":"红色",
                    "license_plate_date":"2017-09",
                    "url":"https://www.che168.com/dealer/367608/35024128.html?pvareaid=100519&userpid=320000&usercid=320100"
                }
            },
            {
                "_index":"ienterprise_jiaxuan_market_price_1573504339051",
                "_type":"default",
                "_id":"31f528d5-5bc7-406a-8c71-283cfb01a8fe",
                "_score":0,
                "_source":{
                    "series_name":"凯迪拉克ATS-L",
                    "brand_name":"凯迪拉克",
                    "location_city_code":"00859",
                    "price":"17.80",
                    "site":"che168",
                    "publish_date":null,
                    "mileage":"1",
                    "model_name":"凯迪拉克ATS-L 2017款 28T 时尚型",
                    "model_code":"13835-n",
                    "location":"南京",
                    "financial_special_price":null,
                    "id":"31f528d5-5bc7-406a-8c71-283cfb01a8fe",
                    "license_plate_city":"南京",
                    "color":"黑色",
                    "license_plate_date":"2017-09",
                    "url":"https://www.che168.com/dealer/380348/35169028.html?pvareaid=100519&userpid=320000&usercid=320100"
                }
            },
            {
                "_index":"ienterprise_jiaxuan_market_price_1573504339051",
                "_type":"default",
                "_id":"a822bd02-efae-487a-bb29-8ce37bddd1e4",
                "_score":0,
                "_source":{
                    "series_name":"凯迪拉克ATS-L",
                    "brand_name":"凯迪拉克",
                    "location_city_code":"00859",
                    "price":"17.98",
                    "site":"che168",
                    "publish_date":null,
                    "mileage":"6",
                    "model_name":"凯迪拉克ATS-L 2017款 28T 时尚型",
                    "model_code":"13835-n",
                    "location":"南京",
                    "financial_special_price":null,
                    "id":"a822bd02-efae-487a-bb29-8ce37bddd1e4",
                    "license_plate_city":"南京",
                    "color":"红色",
                    "license_plate_date":"2017-09",
                    "url":"https://www.che168.com/dealer/367608/34718002.html?pvareaid=100519&userpid=320000&usercid=320100"
                }
            },
            {
                "_index":"ienterprise_jiaxuan_market_price_1573504339051",
                "_type":"default",
                "_id":"b657e0d0-09bc-4c7d-b979-a991f9786cdf",
                "_score":0,
                "_source":{
                    "series_name":null,
                    "brand_name":null,
                    "location_city_code":"00859",
                    "price":"17.80",
                    "site":"che168",
                    "publish_date":null,
                    "mileage":"4.8",
                    "model_name":"凯迪拉克ATS-L 2017款 28T 时尚型",
                    "model_code":"13835-n",
                    "location":"南京",
                    "financial_special_price":null,
                    "id":"b657e0d0-09bc-4c7d-b979-a991f9786cdf",
                    "license_plate_city":null,
                    "color":"白色",
                    "license_plate_date":"2017-12",
                    "url":"https://www.che168.com/lianmeng/109829/34988219.html?pvareaid=100519&userpid=320000&usercid=320100"
                }
            }
        ]
    }
}
View Code

 

ES原理:

ES的组成:【cluster【nodes【index【shard(Lucene Index)【segment】】】】】

Segment内部

有着许多数据结构

  • Inverted Index
  • Stored Fields
  • Document Values
  • Cache

参考文档:https://mp.weixin.qq.com/s/8QsWEdNe-rovdJPkyzz8Zg

posted @ 2019-11-14 13:39  YOU_CAN  阅读(257)  评论(0编辑  收藏  举报