builder.withSort(new FieldSortBuilder("goodsLabel.sortSeq").order(SortOrder.DESC)
.setNestedFilter(QueryBuilders.termQuery("goodsLabel.dictId", labelId))); //排序内嵌过滤
字段的索引为:
多字段属性:
# 商品标签 1->6个标签 (eff_flag为1)
"goodsLabel":{
"properties":{
"dictId":{ # 字典表id
"type":"long",
"index":"not_analyzed",
"store":"true"
},
"sortSeq":{ #排序序号
"type": "long",
"store": "true",
"index": "not_analyzed",
"fielddata": {
"loading": "lazy"
}
}
}
}
对应的dsl语句是:
{
"from" : 0,
"size" : 50,
"query" : {
"bool" : {
"must" : [ {
"multi_match" : {
"query" : "毛衣",
"fields" : [ "goodsCode", " goodsName", " partCode", " partName" ]
}
}, {
"term" : {
"companyId" : 239
}
}, {
"term" : {
"buscontsId" : 1004002
}
} ]
}
},
"sort" : [ {
"goodsLabel.sortSeq" : {
"nested_filter" : {
"term" : {
"goodsLabel.dictId" : "10080104"
}
},
"order" : "asc"
}
}, {
"_score" : { }
} ]
}
想要对goodsLabel.dictId 为10080104的商品进行排序;
2 个回复
wokeyi
赞同来自:
wokeyi
赞同来自:
首先,索引的字段需要指定类型为nested:
搜索时需要指定嵌套的路径:
对应的java代码: