文章目录
概述普通match转换为term+shouldand match转换为term+mustminimum_should_match如何转换概述
继续跟中华石杉老师学习ES,第七篇
课程地址: /view/55
普通match转换为term+should
上一篇博文中我们 使用了 搜索标题中包含java或elasticsearch的blog 这个例子
GET /forum/article/_search{"query": {"match": {"title": "java elasticsearch"}}}
我们通过分词器查看,可以知道 es是把 java和elasticsearch放到了倒排索引中,
那es是如何查询的呢? 我们通过 profile
GET /forum/article/_search{"profile": "true", "query": {"match": {"title": "java elasticsearch"}}}
或者kibana提供的
使用诸如上面的match query进行多值搜索的时候,es会在底层自动将这个match query转换为bool的语法 .bool should,指定多个搜索词,同时使用term query
等同于
GET /forum/_search{"query": {"bool": {"should": [{"term": {"title": "java"}},{"term": {"title": "elasticsearch"}}]}}}
and match转换为term+must
搜索标题中包含java和elasticsearch的blog 中的
GET /forum/_search{"query": {"match": {"title": {"query": "java elasticsearch","operator": "and"}}}}
and match转换为term+must
等同于
GET /forum/_search{"query": {"bool": {"must": [{"term": {"title": "java"}},{"term": {"title": "elasticsearch"}}]}}}
minimum_should_match如何转换
搜索包含java,elasticsearch,spark,hadoop,4个关键字中,至少3个的blog
GET /forum/_search{"query": {"match": {"title": {"query": "java elasticsearch hadoop spark","minimum_should_match": 3}}}}
等同于
GET /forum/_search{"query": {"bool": {"should": [{"term": {"title": "java"}},{"term": {"title": "elasticsearch"}},{"term": {"title": "hadoop"}},{"term": {"title": "spark"}}],"minimum_should_match": 3}}}