easy-es icon indicating copy to clipboard operation
easy-es copied to clipboard

nested嵌套字段排序支持

Open jqlin2019 opened this issue 2 years ago • 1 comments

非常感谢大佬的开源! 在做nested测试的时候发现排序相关问题。

版本2.0.0-beta4 在org.dromara.easyes.test.nested.NestedTest.java下进行测试

    @Test
    public void testNestedMatchSort() {
        // 嵌套查询排序
        LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
        wrapper.nested(FieldUtils.val(Document::getUsers), w ->
                w.orderByAsc("users.faqs.answer.keyword")
        );
        List<Document> documents = documentMapper.selectList(wrapper);
        System.out.println(documents);
    }

得到DSL

{
    "size":10000,
    "query":{
        ......
    },
    "sort":[
       {
           "users.faqs.answer.keyword":{
                "order":"asc"
           }
       }
    ]
}

期望的dsl

......
"sort":[
    {
        "users.faqs.answer.keyword":{
            "order":"asc",
            "nested":{
                 "path":"users",
                 "nested":{
                     "path":"users.faqs"
                  }
            }
        }
    }
]
......

参考 https://juejin.cn/post/7114548789511192590#heading-0

jqlin2019 avatar Dec 27 '23 09:12 jqlin2019

用mixed混合查询可以拼接

    @Test
    public void testNestedMatchMixedSort() {
        // 嵌套查询排序
        LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
        FieldSortBuilder fieldSortBuilder = SortBuilders.fieldSort("users.faqs.answer.keyword");
        fieldSortBuilder.setNestedSort(new NestedSortBuilder("users").setNestedSort(new NestedSortBuilder("users.faqs")));
        wrapper.sort(fieldSortBuilder);
        List<Document> documents = documentMapper.selectList(wrapper);
        System.out.println(documents);
    }

jqlin2019 avatar Dec 29 '23 06:12 jqlin2019