Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.2k views
in Technique[技术] by (71.8m points)

elasticsearch中wildcard通配符问号"?"使用问题

碰到es查询时通配符问题,官网中?为匹配任何单个字符,但在使用中出现问题。于是举个例子如下(别名省略)

PUT /book_v1
{
  "mappings": {
     "properties": {
        "name": {
          "type": "text",
          "analyzer": "ik_max_word",
        }
      }
  }
}

PUT几个数据,如 "三国演义", "三国志", "三国人", "三毛", "三国", "红楼梦", "神雕侠侣", "红"
在执行查询时,

POST /book/_search
{
  "query": {
    "wildcard": {
      "name": {
        "value": "*"
      }
    }
  }
}

结果所有匹配。将 *换为问号?,结果为多个,不是一个,也不是全部
再次查询

POST /book/_search
{
  "query": {
    "wildcard": {
      "name": {
        "value": "三?"
      }
    }
  }
}

结果并不是 “三毛”,而是所有和 “三”有关的全部查询到。
再次更换查询

POST /book/_search
{
  "query": {
    "wildcard": {
      "name": {
        "value": "三国?"
      }
    }
  }
}

此次结果只有“三国志”和“三国人”。
因此,通配符问号? 再没有前缀字符、只有一个前缀字符和多个前缀字符时占位符作用时不一样的?
注:使用版本7.6.2


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...