minimum_should_match 今天药忘吃喽~ 2022-11-06 05:53 119阅读 0赞 > * [https://www.elastic.co/guide/en/elasticsearch/reference/7.x/query-dsl-minimum-should-match.html][https_www.elastic.co_guide_en_elasticsearch_reference_7.x_query-dsl-minimum-should-match.html] > * [https://www.elastic.co/guide/cn/elasticsearch/guide/current/index.html][https_www.elastic.co_guide_cn_elasticsearch_guide_current_index.html] > * [https://www.elastic.co/guide/cn/elasticsearch/guide/current/\_how\_match\_uses\_bool.html][https_www.elastic.co_guide_cn_elasticsearch_guide_current_how_match_uses_bool.html] > * [https://www.elastic.co/guide/en/elasticsearch/reference/7.x/full-text-queries.html][https_www.elastic.co_guide_en_elasticsearch_reference_7.x_full-text-queries.html] -------------------- # 1 测试数据 # ### 删除 DELETE /test_idx_2 ### 查询 GET /test_idx_2/_search ### 批量插入 POST _bulk {"index":{"_index":"test_idx_2","_id":1}} {"title":"a"} {"index":{"_index":"test_idx_2","_id":2}} {"title":"a b"} {"index":{"_index":"test_idx_2","_id":3}} {"title":"a b c"} {"index":{"_index":"test_idx_2","_id":4}} {"title":"a b c d"} {"index":{"_index":"test_idx_2","_id":5}} {"title":"a b c d e"} -------------------- # 2 使用 # 可以取值:[https://www.elastic.co/guide/en/elasticsearch/reference/7.x/query-dsl-minimum-should-match.html][https_www.elastic.co_guide_en_elasticsearch_reference_7.x_query-dsl-minimum-should-match.html] { "query":{ "match":{ "字段名":{ "query":"查询内容", "operator":"or", "minimum_should_match":"参数" } } } } 插入测试数据 ### 删除 DELETE /test_idx_2 ### 查询 GET /test_idx_2/_search ### 批量插入 POST _bulk {"index":{"_index":"test_idx_2","_id":1}} {"title":"a"} {"index":{"_index":"test_idx_2","_id":2}} {"title":"a b"} {"index":{"_index":"test_idx_2","_id":3}} {"title":"a b c"} {"index":{"_index":"test_idx_2","_id":4}} {"title":"a b c d"} {"index":{"_index":"test_idx_2","_id":5}} {"title":"a b c d e"} "operator":"or",匹配到一个词即可查询到,所以这里所有的文档都能匹配到 ### 全部匹配,5个 POST /test_idx_2/_search { "query": { "match": { "title": { "query": "a b c d e", "operator": "or" } } } } "minimum\_should\_match": "75%",查询条件被分为5个词,5\*75%=3.75,向下取整为3,也就是查询的文档分词后需要匹配3个词才可以 POST /test_idx_2/_search { "query": { "match": { "title": { "query": "a b c d e", "operator": "or", "minimum_should_match": "75%" } } } } "minimum\_should\_match":"-25%",逆向匹配和正向匹配相反,比如我们可以近似理解为\-25%和75%表示的是一个意思,但是有些小小的差异。查询条件被分为5个词,逆向匹配-25%,5\*25%=1.25,取整是1,**5-1=4**,即要匹配4个词。 POST /test_idx_2/_search { "query": { "match": { "title": { "query": "a b c d e", "operator": "or", "minimum_should_match": "-25%" } } } } match并不去看分词后的顺序,只要能匹配上即可 ### 分词后的内容是无顺序的 POST /test_idx_2/_search { "query": { "match": { "title": { "query": "a b c", "operator": "and" } } } } POST /test_idx_2/_search { "query": { "match": { "title": { "query": "c b a", "operator": "and" } } } } > [https://blog.csdn.net/xiao\_jun\_0820/article/details/51095521][https_blog.csdn.net_xiao_jun_0820_article_details_51095521] [https_www.elastic.co_guide_en_elasticsearch_reference_7.x_query-dsl-minimum-should-match.html]: https://www.elastic.co/guide/en/elasticsearch/reference/7.x/query-dsl-minimum-should-match.html [https_www.elastic.co_guide_cn_elasticsearch_guide_current_index.html]: https://www.elastic.co/guide/cn/elasticsearch/guide/current/index.html [https_www.elastic.co_guide_cn_elasticsearch_guide_current_how_match_uses_bool.html]: https://www.elastic.co/guide/cn/elasticsearch/guide/current/_how_match_uses_bool.html [https_www.elastic.co_guide_en_elasticsearch_reference_7.x_full-text-queries.html]: https://www.elastic.co/guide/en/elasticsearch/reference/7.x/full-text-queries.html [https_blog.csdn.net_xiao_jun_0820_article_details_51095521]: https://blog.csdn.net/xiao_jun_0820/article/details/51095521
还没有评论,来说两句吧...