zoukankan      html  css  js  c++  java
  • elasticsearch-搜索-评分(四)

    Dis Max Query

    打分测试

    PUT /blogs/_doc/1
    {
        "title": "Quick brown rabbits",
        "body":  "Brown rabbits are commonly seen."
    }
    
    PUT /blogs/_doc/2
    {
        "title": "Keeping pets healthy",
        "body":  "My quick brown fox eats rabbits on a regular basis."
    }

    搜索

    POST /blogs/_search
    {
        "query": {
            "bool": {
                "should": [
                    { "match": { "title": "Brown fox" }},
                    { "match": { "body":  "Brown fox" }}
                ]
            }
        }
    }

    文档1会排在前面 

    原因?shoud打分原理

    1.查询should2个语句

    2.加和2个评分

    3.乘以匹配语句的总数

    4.除以所有语句总数

    纠正

    dis_max会将语句中 匹配度最高的返回 而不会相加

    POST blogs/_search
    {
        "query": {
            "dis_max": {
                "queries": [
                    { "match": { "title": "Quick pets" }},
                    { "match": { "body":  "Quick pets" }}
                ]
            }
        }
    }

    Multi Match

    打分测试

    1.添加索引

    PUT /titles
    {
      "mappings": {
        "properties": {
          "title": {
            "type": "text",
            "analyzer": "english"
          }
        }
      }
    }

    2.录入数据

    POST titles/_bulk
    { "index": { "_id": 1 }}
    { "title": "My dog barks" }
    { "index": { "_id": 2 }}
    { "title": "I see a lot of barking dogs on the road " }

    3.搜索

    GET titles/_search
    {
      "query": {
        "match": {
          "title": "barking dogs"
        }
      }
    }

    文档1会排在前面,barking dogs 分词 分成了barking dog   但是因为1更短所以排在前面

    纠正

    DELETE /titles
    PUT /titles
    {
      "mappings": {
        "properties": {
          "title": {
            "type": "text",
            "analyzer": "english",
            "fields": {"std": {"type": "text","analyzer": "standard"}}//增加一个分词字段 采用standard分词
          }
        }
      }
    }
    GET /titles/_search
    {
       "query": {
            "multi_match": {
                "query":  "barking dogs",
                "type":   "most_fields",
                "fields": [ "title", "title.std" ]//搜索  2个搜索的评分相加 可以让文档2排在前面
            }
        }
    }
    GET /titles/_search
    {
       "query": {
            "multi_match": {
                "query":  "barking dogs",
                "type":   "most_fields",
                "fields": [ "title^10", "title.std" ] //可以设置字段的权重
            }
        }
    }

    设置and关系

    GET /titles/_search
    {
       "query": {
            "multi_match": {
                "query":  "barking dogs",
                "type":   "cross_fields",
                "operator":"and",
                "fields": [ "title^10", "title.std" ] //可以设置字段的权重
            }
        }
    }
  • 相关阅读:
    python初学第一节课
    关于float类型和u32类型问题
    今天的工作状态,规划未来一段时间内必须完成的事情(Record the working status of today,planning for the next period of time must be completed)
    STM32 硬件I2C初始化 I2C1_GPIO_AF_Config
    C语言编程规范--------12 宏
    C语言编程规范--------11 代码测试、维护
    C语言编程规范--------10 代码编辑、编译、审查
    C语言编程规范--------9 质量保证
    C语言编程规范--------8 效率
    C语言编程规范--------7 可测性
  • 原文地址:https://www.cnblogs.com/LQBlog/p/13688040.html
Copyright © 2011-2022 走看看