"properties": {
"columns": {
"properties": {
"id": {
"type": "keyword",
"index": "not_analyzed"
},
"name": {
"type": "keyword",
"index": "not_analyzed"
},
"siteId": {
"type": "keyword",
"index": "not_analyzed"
}
}
},
"text": {
"type": "text",
"store": "false",
"analyzer": "hanlp",
"fields": {
"keyword": {
"type": "text",
"index": "not_analyzed",
"fielddata": "true"
}
}
}
}
为了实现模糊查询,我使用以下方式进行查询:
GET/book_page/book_page/_search
{
"from": 0,
"size": 10,
"query": {
"bool": {
"must": [
{
"script": {
"script": {
"inline": "doc['text_nlp_sore.keyword'].value!=null&&doc['text_nlp_sore.keyword'].value.indexOf(params.a)!=-1",
"lang": "painless",
"params": {
"a": "中文"
}
}
}
}
]
}
},
"sort": [
{
"_script": {
"script": {
"inline": "String myText=doc['text_nlp_sore.keyword'].value;if(myText!=null){int count=0;int index=-1;while((index=myText.indexOf(params.a))!=-1){count++;myText=myText.substring(index+params.a.length())}return Math.log(count);}else{return 0;}",
"lang": "painless",
"params": {
"a": "中文"
}
},
"type": "string",
"order": "desc"
}
},
{
"bookDate_date_sore": {
"order": "desc"
}
}
],
"highlight": {
"fields": {
}
}
}
但是什么搜索不出来,我怀疑doc['text_nlp_sore.keyword'].value 是分词吗?但我明确地设置了 "index": "not_analyzed"。所以我想知道我在这一部分是否犯了错误?请告诉我。谢谢你