1.keyword类型不分词,
text类型分词,
但是keyword类型有字节长度限制,长度为
如果超长文本,而且不需要分词,则可以设置为
text,被指定字段不分词,例:
"introduces" : {
"type" : "text",
"index": false
},
- 多条件搜索排序,可以通过对查询字段设置权重,排序时,对算分进行排序
例:
builder=QueryBuilders.boolQuery()
.should(QueryBuilders.matchQuery("extension_field",content).boost(500).operator(Operator.AND))
.should(QueryBuilders.matchQuery("names",content).boost(200).operator(Operator.AND))
.should(QueryBuilders.matchQuery("brandname",content).boost(100).operator(Operator.AND))
.should(QueryBuilders.matchQuery("oneName",content).boost(2).operator(Operator.AND))
.should(QueryBuilders.matchQuery("twoName",content).boost(2).operator(Operator.AND))
.should(QueryBuilders.matchQuery("threeName",content).boost(2).operator(Operator.AND));
if(sortField!=null&&!"".equals(sortField)){
//按照用户选择进行排序
if ("asc".equals(sort)){
searchSourceBuilder.sort(sortField, SortOrder.ASC).sort("_score", SortOrder.DESC);
}else if("desc".equals(sort)){
searchSourceBuilder.sort(sortField, SortOrder.DESC).sort("_score", SortOrder.DESC);
}
}
else {
// 按照默认,区分企业和个人不同用户类型来排序
if (userType==1){
searchSourceBuilder.sort("personSort",SortOrder.ASC).sort("_score", SortOrder.DESC);
}else {
searchSourceBuilder.sort("enterpriseSort",SortOrder.ASC).sort("_score", SortOrder.DESC);
}
}
//设置minimum_should_match,使must和shoud同时生效
boolquerybuilder.minimumShouldMatch(1);
20220420:排序不准确
问题情况:
解决方法:
原因:
排序问题。
数组类型是nested类型时,对数组中的字段排序,实际时对数组里面的二级对象排序,
普通数组类型排序,排序的是值