将mysql排序语句 ORDER BY FIND_IN_SET(bcp.tree_node_type,'6,5,4,3,2,1'), CONVERT(bcp.tree_case_name USING gbk),bcp.create_time,bc.case_name 转换成ElasticSearch排序
时间: 2024-02-21 19:57:53 浏览: 117
在ElasticSearch中,您可以使用“sort”参数指定您要按哪个字段进行排序。在这种情况下,您需要按照以下方式转换排序语句:
```
{
"sort": [
{
"tree_node_type": {
"order": "desc",
"nested": {
"path": "bcp",
"filter": {
"bool": {
"must": [
{ "term": { "bcp.tree_node_type": "6" } },
{ "term": { "bcp.tree_node_type": "5" } },
{ "term": { "bcp.tree_node_type": "4" } },
{ "term": { "bcp.tree_node_type": "3" } },
{ "term": { "bcp.tree_node_type": "2" } },
{ "term": { "bcp.tree_node_type": "1" } }
]
}
}
}
}
},
{
"tree_case_name": {
"order": "asc",
"nested": {
"path": "bcp",
"filter": {
"bool": {
"must": [
{ "exists": { "field": "bcp.tree_case_name" } }
]
}
}
}
}
},
{ "create_time": { "order": "asc" } },
{ "case_name": { "order": "asc" } }
]
}
```
在上面的代码中,我们使用“sort”参数指定了要按哪些字段排序,并按以下方式转换排序语句:
1. 首先按“tree_node_type”字段进行排序。我们使用“nested”参数指定“bcp”字段是嵌套的,并使用“filter”参数指定我们要过滤的条件。我们使用“term”查询指定我们要匹配的值,然后按照“6,5,4,3,2,1”的顺序进行匹配。最后,我们按“desc”顺序排序,使结果与原始的MySQL排序语句相同。
2. 接下来按“tree_case_name”字段排序。我们使用“exists”查询指定我们要过滤掉值为null的记录,并按“asc”顺序排序。
3. 然后按“create_time”字段进行排序,并按“asc”顺序排序。
4. 最后按“case_name”字段进行排序,并按“asc”顺序排序。
请注意,如果您正在使用ElasticSearch 7.x版本,则可能需要将以上查询中的“nested”参数替换为“inner_hits”参数。
阅读全文
相关推荐
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231044955.png)
![-](https://img-home.csdnimg.cn/images/20241231044955.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![application/pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![gz](https://img-home.csdnimg.cn/images/20210720083447.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![gz](https://img-home.csdnimg.cn/images/20210720083447.png)
![doc](https://img-home.csdnimg.cn/images/20241231044833.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)