es 的match query底层原理

1、知识点:match query底层会自动转换为term+should/must方式

2、实例剖析

(1)普通match如何转换为term+should

{
  "match" : {"title" : "java elasticsearch"}
}

ES会自动给我们转换为如下

{
  "bool" : {
    "should" : [
        {"term" : {"title" : "java"}},
        {"term" : {"title" : "elasticsearch"}}
    ]
  }
}

(2)operator:and如何转换为term+must

{
  "match" : {
    "title" : {
       "query" : "java elasticsearch",
       "operator" : and
    }
  }
}
{
  "bool" : {
    "must" : [
       { "term": { "title": "java" }},
       { "term": { "title": "elasticsearch"   }}
    ]
  }
}

(3)minimum_should_match如何转换

{
  "match" : {
    "title" : {
      "query" : "java elasticsearch hadoop spark",
      "minimum_should_match" : "75%"
    }
  }
}
{
  "bool" : {
    "should" : [
      {"term" : {"title" : "java"}},
      {"term" : {"title" : "elasticsearch"}},
      {"term" : {"title" : "hadoop"}},
      {"term" : {"title" : "spark"}}
    ],
    "minimum_should_match" : 3
  }
}



转自于:https://www.jianshu.com/p/3c4f98bffb34

posted @ 2019-06-21 16:17  上海小墨子  阅读(1090)  评论(0编辑  收藏  举报