问题:使用ES字段折叠去重时报错:
collapse is not supported for the field [goodsId] of the type [text]]
查询代码:
//指定按照goodsId字段折叠去重
CollapseBuilder collapseBuilder = new CollapseBuilder("goodsId");
searchQuery.setCollapseBuilder(collapseBuilder);
解决方法:
text是用于分词的,不支持collapse,只需将字段名goodsId换成goodsId.keyword即可;
修改后查询代码:
//指定按照goodsId字段折叠去重
CollapseBuilder collapseBuilder = new CollapseBuilder("goodsId.keyword");
searchQuery.setCollapseBuilder(collapseBuilder);