es中 minimum_should_match

minimum_should_match 来确认几个匹配项。

插入数据

PUT faq/faq/2

{

  "title": "史上最全各国进口",

  "answerText": "史上最全各国进口"

}

查看title存在的term

GET faq/faq/2/_termvectors?fields=title

主要结果如下:

   "terms": {

        "史上": {

          "term_freq": 1,

          "tokens": [

            {

              "position": 0,

              "start_offset": 0,

              "end_offset": 2

            }

          ]

        },

        "各国": {

          "term_freq": 1,

          "tokens": [

            {

              "position": 2,

              "start_offset": 4,

              "end_offset": 6

            }

          ]

        },

        "最全": {

          "term_freq": 1,

          "tokens": [

            {

              "position": 1,

              "start_offset": 2,

              "end_offset": 4

            }

          ]

        },

        "进口": {

          "term_freq": 1,

          "tokens": [

            {

              "position": 3,

              "start_offset": 6,

              "end_offset": 8

            }

          ]

        }

      }

}

 

一共有5个trem

 

输入要查询的条件

  GET /_analyze

{

  "analyzer": "ik_max_word",

  "text": "史上12最全1231各国"

}

显示的trem

{

  "tokens": [

    {

      "token": "史上",

      "start_offset": 0,

      "end_offset": 2,

      "type": "CN_WORD",

      "position": 0

    },

    {

      "token": "12",

      "start_offset": 2,

      "end_offset": 4,

      "type": "ARABIC",

      "position": 1

    },

    {

      "token": "最全",

      "start_offset": 4,

      "end_offset": 6,

      "type": "CN_WORD",

      "position": 2

    },

    {

      "token": "1231",

      "start_offset": 6,

      "end_offset": 10,

      "type": "ARABIC",

      "position": 3

    },

    {

      "token": "各国",

      "start_offset": 10,

      "end_offset": 12,

      "type": "CN_WORD",

      "position": 4

    }

  ]

}

一共有5个trems

 

 

 

  GET faq/faq/_search

{

  "query": {

    "match": {

      "title": {

        "query": "史上12最全1231各国",

        "minimum_should_match": "79%"

      }

    }

  }

}

分词后有3个符合查询添加 minimum_should_match": "79%" 是3.95 因为是想下取整 所以是3 可以查询到数据


 

  GET faq/faq/_search

{

  "query": {

    "match": {

      "title": {

        "query": "史上12最全1231各国",

        "minimum_should_match": "80%"

      }

    }

  }

}

最少要4个匹配,因为只有3个匹配 所以不符合。

GET faq/faq/_search

{

  "query": {

    

    "bool": {

      

      "must": [

        {"match": {

          "id": "1559465463986"

        }}

      ],

      "should": [

        {"match": {

          "title": "TEX"

        }

        }

        ,{

          "match": {

            "answerTex": "TEX"

          }

        }

      

      ],

      "minimum_should_match": 0

      

    }

    

  }

}

Bool 查询里 代表 有几个should 里面的值 需要匹配, 如果不写 相当于是0个 表示不要匹配minimum_should_match的东西。

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值