es match之match_phrase、match_phrase_prefix


PUT s1/_doc/1
{
  "title": "中国是世界人口最多的国家"
}

PUT s1/_doc/2
{
  "title": "美国是世界上军事最强的国家"
}

PUT s1/_doc/3
{
  "title": "日本是世界上渔业最丰富的国家"
}

GET s1/_search
{
  "query": {
    "match": {
      "title": "中国"
    }
  }
}

GET s1/_search
{
  "query": {
    "match_phrase": {
      "title": "中国"
    }
  }
}

GET s1/_search
{
  "query": {
    "match_phrase": {
      "title": {
        "query": "中国人口",
        "slop": 5
      }
    }
  }
}


# 最左前缀查询

PUT s2/_doc/1
{
  "title": "beautiful girl"
}

PUT s2/_doc/2
{
  "title": "beautiful so"
}

GET s2/_search
{
  "query": {
    "match_phrase_prefix": {
      "title": "b"
    }
  }
}


PUT s2/_doc/3
{
  "t1": "xiong beautiful boy", 
  "t2": "qiu beautiful"
}

# 指定查询的字段,自动分词
GET s2/_search
{
  "query": {
    "multi_match": {
      "query": "beautiful boy",
      "fields": ["title"]
    }
  }
}


# 指定查询的字段,短句,不分词
GET s2/_search
{
  "query": {
    "multi_match": {
      "query": "xiong",
      "fields": ["t1", "t2", "title"],
      "type": "phrase"
    }
  }
}


# 指定查询的字段,短句,最左前缀原则
GET s2/_search
{
  "query": {
    "multi_match": {
      "query": "be",
      "fields": ["t1", "t1", "title"],
      "type": "phrase_prefix"
    }
  }
}

GET s2/_search
{
  "query": {
    "multi_match": {
      "query": "be",
      "fields": ["t1", "t1", "title"],
      "type": "phrase"
    }
  }
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM