找出一个属性中的独立单词是没有问题的,但有时候想要精确匹配一系列单次或者短语。比如,我们想执行这样一个查询,仅匹配同时包含“rock” 和 “climbing”,并且二者以短语“rock climbing”的形式紧挨着的雇员记录

    为此对 match 查询稍作调整,使用一个叫做match_phrase 的查询。

    1. GET /megacorp/employee/_search
    2. {
    3. "query" : {
    4. "match_phrase" : {
    5. "about" : "rock climbing"
    6. }
    7. }
    8. }

    毫无悬念,返回结果仅有 John Smith 的文档。

    {
       ...
       "hits": {
          "total":      1,
          "max_score":  0.23013961,
          "hits": [
             {
                ...
                "_score":         0.23013961,
                "_source": {
                   "first_name":  "John",
                   "last_name":   "Smith",
                   "age":         25,
                   "about":       "I love to go rock climbing",
                   "interests": [ "sports", "music" ]
                }
             }
          ]
       }
    }