elasticsearch中⼏种判断条件
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
if (Operator().equals(MatchType.equal.name())) {
if (Type().equals("int")) {
boolQueryBuilder.must(QueryBuilders.Attribute(), Keyword()));
equals不等于} else {
boolQueryBuilder.must(QueryBuilders.Attribute() + ".keyword", Keyword())); }
} else if (Operator()._equal.name())) {
boolQueryBuilder.mustNot(QueryBuilders.Attribute() + ".keyword", Keyword())); } else if (Operator().ains.name())) {
if (Type().equals("check")) {
ArrayList arrayList = (ArrayList) Keyword();
if (arrayList.size() > 0) {
if ((0) instanceof Long || (0) instanceof Integer) {
List<Long> listID = (List<Long>) (Keyword());
boolQueryBuilder.Attribute(), listID));
} else if ((0) instanceof String) {
List<String> listKey = (List<String>) Keyword();
for (String key : listKey
) {
boolQueryBuilder.should(QueryBuilders.Attribute() + ".keyword", key));
}
boolQueryBuilder.minimumShouldMatch(1);
}
}
} else {
if (StringObjUtil.Keyword().toString())) {
boolQueryBuilder.must(QueryBuilders.Attribute(), "*" + Keyword() + "*"));
} else {
boolQueryBuilder.must(QueryBuilders.Attribute(), Keyword()));
}
}
} else if (Operator()._contains.name())) {
if (Type().equals("check")) {
ArrayList arrayList = (ArrayList) Keyword();
if (arrayList.size() > 0) {
if ((0) instanceof Long || (0) instanceof Integer) {
boolQueryBuilder.Attribute(), arrayList));
} else if ((0) instanceof String) {
List<String> listKey = (List<String>) Keyword();
for (String key : listKey
) {
boolQueryBuilder.mustNot(QueryBuilders.Attribute() + ".keyword", key));
}
}
}
} else {
if (StringObjUtil.Keyword().toString())) {
boolQueryBuilder.mustNot(QueryBuilders.Attribute(), "*" + Keyword() + "*"));
} else {
boolQueryBuilder.mustNot(QueryBuilders.Attribute(), Keyword()));
}
}
} else if (Operator().equals(MatchType.isnull.name())) {
if (Type().equals("check")){
boolQueryBuilder.Attribute()));
}else {
boolQueryBuilder.mustNot(QueryBuilders.Attribute(), "*"));
}
} else if (Operator()._isnull.name())) {
} else if (Operator()._isnull.name())) {
if (Type().equals("check")){
boolQueryBuilder.Attribute()));
}else {
boolQueryBuilder.must(QueryBuilders.Attribute(), "*"));
}
} else if (Operator().equals(MatchType.range.name())) {
if (Type().equals("date")) {
if (Keyword().toString().contains("~")) {
String[] dates = Keyword().toString().split("~");
LocalDateTime start = LocalDateTime.parse(dates[0], dateTimeFormatter);
LocalDateTime end = LocalDateTime.parse(dates[1], dateTimeFormatter);
boolQueryBuilder.must(QueryBuilders.Attribute()).from(start).to(end)); }
} else {
boolQueryBuilder.must(QueryBuilders.Attribute()));
}
} else if (Operator().ame())) {
if (Type().equals("date")) {
LocalDateTime start = LocalDateTime.Keyword().toString(), dateTimeFormatter); boolQueryBuilder.must(QueryBuilders.Attribute()).gt(start));
} else {
boolQueryBuilder.must(QueryBuilders.Attribute()).Keyword())); }
} else if (Operator().equals(MatchType.lt.name())) {
if (Type().equals("date")) {
LocalDateTime start = LocalDateTime.Keyword().toString(), dateTimeFormatter); boolQueryBuilder.must(QueryBuilders.Attribute()).lt(start));
} else {
boolQueryBuilder.must(QueryBuilders.Attribute()).Keyword())); }
}
elasticsearch中,对应不同的数据类型,查询不同的条件查询基本写法。
contains("包含"),
/**
* 是
*/
equal("等于"),
/**
* 包含
*/
not_equal("不等于"), /**
* 包含
*/
not_contains("不包含"), startsWith("开头匹配"), endsWith("结尾匹配"), isnull("为空"),
not_isnull("不为空"), range("范围"),
gt("⼤于"),
lt("⼩于");
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论