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" ] //可以设置字段的权重
            }
        }
    }
  • 相关阅读:
    7.5_链表_链表中添加结点
    【链表】创建新结点
    【单链表】头插法 & 尾插法
    7.5_链表_添加元素_尾插法/头插法
    7.5_链表_创建链表
    7.4_结构体_返回结构体的函数
    通俗的理解一下生成式对抗网络(GAN)
    Linux中如何让进程(或正在运行的程序)到后台运行?
    anaconda搭建本地源(加速访问),内网源(无外网访问)
    Ubuntu18.04(16和14也可以) 安装独立显卡后开机黑屏
  • 原文地址:https://www.cnblogs.com/LQBlog/p/13688040.html
Copyright © 2011-2022 走看看