我试图找出索引中的文档,无论它的字段值是否为索引中的小写或大写。
这是我用自定义分析器设计的索引结构。我是分析人员的新手,我可能错了。这是它的外观:
POST arempris/emptagnames
{
"settings": {
"analyzer": {
"lowercase_keyword": {
"type": "custom",
"tokenizer": "keyword",
"filter": "lowercase"
}
}
},
"mappings" : {
"emptags":{
"properties": {
"employeeid": {
"type":"integer"
},
"tagName": {
"type": "text",
"fielddata": true,
"analyzer": "lowercase_keyword"
}
}
}
}
}
在java后端,我使用BoolQueryBuilder首先使用employeeids查找标记名。这就是我编写的用于获取值的内容:
BoolQueryBuilder query = new BoolQueryBuilder();
query.must(new WildcardQueryBuilder("tagName", "*June*"));
query.must(new TermQueryBuilder("employeeid", 358));
SearchResponse response12 = esclient.prepareSearch(index).setTypes("emptagnames")
.setQuery(query)
.execute().actionGet();
SearchHit[] hits2 = response12.getHits().getHits();
System.out.println(hits2.length);
for (SearchHit hit : hits2) {
Map map = hit.getSource();
System.out.println((String) map.get("tagName"));
}
当我将要搜索的标记指定为小写的“june”时,它工作正常,但是当我在WildCardQueryBuilder中将其指定为“June”时,字母为大写,我没有得到任何匹配。
让我知道我犯了什么错误。非常感谢您的帮助和提前感谢。
答案 0 :(得分:0)
elasticsearch中有两种类型的查询
全文查询的规则是
因此,在这种情况下,您需要将查询更改为此
BoolQueryBuilder query = new BoolQueryBuilder();
query.must(new QueryStringQueryBuilder("tagName:*June*"));
query.must(new TermQueryBuilder("employeeid", 358));
SearchResponse response12 = esclient.prepareSearch(index).setTypes("emptagnames")
.setQuery(query)
.execute().actionGet();
SearchHit[] hits2 = response12.getHits().getHits();
System.out.println(hits2.length);
for (SearchHit hit : hits2) {
Map map = hit.getSource();
System.out.println((String) map.get("tagName"));
}