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的东西。

 

 

 

你可能感兴趣的:(java)