记录一下ES分词以后当前那个字段是没有办法用来进行模糊查询的,但是当我们加入es的字段类型为text的时候,es会自动帮我们创建一个为keyword的字段
代码示例:
创建数据:
http://localhost:9200/forum/article/_bulk
{ "index": { "_id": 1 }}
{ "articleID" : "XHDK-A-1293-#fJ3", "userID" : 1, "hidden": false, "postDate": "2017-01-01" }
{ "index": { "_id": 2 }}
{ "articleID" : "KDKE-B-9947-#kL5", "userID" : 1, "hidden": false, "postDate": "2017-01-02" }
{ "index": { "_id": 3 }}
{ "articleID" : "JODL-X-1937-#pV7", "userID" : 2, "hidden": false, "postDate": "2017-01-01" }
{ "index": { "_id": 4 }}
{ "articleID" : "QQPX-R-3956-#aD8", "userID" : 2, "hidden": true, "postDate": "2017-01-02" }
按分词字段进行模糊查询:
http://localhost:9200/forum/article/_search
{
"query":{
"bool":{
"must":{
"wildcard":{
"articleID":"*JODL*"
}
}
}
}
}
这样我们会发现查不出来数据
按照keyword进行查询:
http://localhost:9200/forum/article/_search
{
"query":{
"bool":{
"must":{
"wildcard":{
"articleID.keyword":"*JODL*"
}
}
}
}
}
就能查询对应结果