Skip to content

Commit

Permalink
Merge pull request #37 from qzhello/main
Browse files Browse the repository at this point in the history
fix: 修复8+版本的doc排序报错与hits total高低版本兼容
  • Loading branch information
qzhello authored May 11, 2024
2 parents cbb28c4 + e56cab8 commit b50fd71
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/main/java/com/ly/ckibana/constants/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public class Constants {

public static final String KEY_NAME = "key";

public static final String DOC_TYPE = "_doc";
/**
* es查询参数关键字.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/ly/ckibana/model/response/Hits.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ public class Hits {
@JsonProperty("max_score")
private long maxScore;

private long total;
private Object total;
}
5 changes: 4 additions & 1 deletion src/main/java/com/ly/ckibana/parser/MsearchParamParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public class MsearchParamParser extends ParamParser {
public void checkTimeInRange(CkRequestContext ckRequestContext) {
if (!isTimeInRange(ckRequestContext)) {
throw new TimeNotInRangeException("查询时间跨度太大,目前支持最大查询区间为:"
+ DateUtils.formatDurationWords(proxyConfigLoader.getKibanaProperty().getProxy().getMaxTimeRange()));
+ DateUtils.formatDurationWords(proxyConfigLoader.getKibanaProperty().getProxy().getMaxTimeRange()));
}
}

Expand Down Expand Up @@ -146,6 +146,9 @@ public void parseSort(JSONObject searchQuery, CkRequestContext ckRequestContext)
each.keySet().forEach(orgField -> {
Map<String, String> columns = ckRequestContext.getColumns();
String ckSortFieldName = ParamConvertUtils.convertUiFieldToCkField(columns, orgField);
if (Constants.DOC_TYPE.equals(ckSortFieldName)) {
return;
}
// 如果该字段在ck中不存在,且无ck_assembly_extension扩展字段,则不放到排序条件中
if (!columns.containsKey(ckSortFieldName) && !columns.containsKey(Constants.CK_EXTENSION)) {
return;
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/ly/ckibana/util/ParamConvertUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.ly.ckibana.util;

import com.ly.ckibana.constants.Constants;
import com.ly.ckibana.model.exception.UnKnownFieldException;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
Expand All @@ -41,7 +42,7 @@ public static String convertUiFieldToCkField(Map<String, String> columns, String
result = StringUtils.trim(result);
}
// 未定义字段不支持查询
if (!columns.containsKey(result)) {
if (!columns.containsKey(result) && !Constants.DOC_TYPE.equals(orgField)) {
throw new UnKnownFieldException(result);
}
return result;
Expand Down

0 comments on commit b50fd71

Please sign in to comment.