[fix](es-catalog)fix error when querying the index ,elasticsearch version 8.9.1 (#24839)

Issue Number: close #24833
This commit is contained in:
Guangdong Liu
2023-10-08 10:19:45 +08:00
committed by GitHub
parent f66708db0e
commit fddef8b473
6 changed files with 52 additions and 5 deletions

View File

@ -39,6 +39,9 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Spliterator;
import java.util.Spliterators;
import java.util.stream.StreamSupport;
/**
* Util for ES, some static method.
@ -110,15 +113,18 @@ public class EsUtil {
// remove dynamic templates, for ES 7.x and 8.x
checkNonPropertiesFields(mappings, arrayFields);
String firstType = mappings.fieldNames().next();
if (!"properties".equals(firstType)) {
// If type is not passed in takes the first type.
//The first parameter may not be properties, so we need to first determine whether it is 7.x or above.
if (StreamSupport.stream(Spliterators
.spliteratorUnknownSize(mappings.fieldNames(), Spliterator.ORDERED), false)
.anyMatch(s -> s.contains("properties"))) {
// Equal 7.x and after
return mappings;
} else {
ObjectNode firstData = (ObjectNode) mappings.get(firstType);
// check for ES 6.x and before
checkNonPropertiesFields(firstData, arrayFields);
return firstData;
}
// Equal 7.x and after
return mappings;
} else {
if (mappings.has(mappingType)) {
ObjectNode jsonData = (ObjectNode) mappings.get(mappingType);