Skip to content

Commit

Permalink
allow zero index
Browse files Browse the repository at this point in the history
Signed-off-by: xinyual <[email protected]>
  • Loading branch information
xinyual committed Nov 25, 2023
1 parent f0a19de commit fcde2a5
Showing 1 changed file with 21 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -214,19 +214,29 @@ private String constructTableInfo(SearchHit [] searchHits, Map<String, MappingMe
Map<String, Object> mappingSource = (Map<String, Object>) mappingMetadata.getSourceAsMap().get("properties");
Map<String, String> fieldsToType = new HashMap<>();
extractNamesTypes(mappingSource, fieldsToType, "");

SearchHit hit = searchHits[0];
Map<String, Object> sampleSource = hit.getSourceAsMap();
Map<String, String> fieldsToSample = new HashMap<>();
for (String key : fieldsToType.keySet()) {
fieldsToSample.put(key, "");
}
extractSamples(sampleSource, fieldsToSample, "");
StringJoiner tableInfoJoiner = new StringJoiner("\n");

for (String key : fieldsToType.keySet()) {
String line = "- " + key + ": " + fieldsToType.get(key) + " (" + fieldsToSample.get(key) + ")";
tableInfoJoiner.add(line);
if (searchHits.length > 0) {
SearchHit hit = searchHits[0];
Map<String, Object> sampleSource = hit.getSourceAsMap();
Map<String, String> fieldsToSample = new HashMap<>();
for (String key : fieldsToType.keySet()) {
fieldsToSample.put(key, "");
}
extractSamples(sampleSource, fieldsToSample, "");


for (String key : fieldsToType.keySet()) {
String line = "- " + key + ": " + fieldsToType.get(key) + " (" + fieldsToSample.get(key) + ")";
tableInfoJoiner.add(line);
}
}
else
{
for (String key : fieldsToType.keySet()) {
String line = "- " + key + ": " + fieldsToType.get(key);
tableInfoJoiner.add(line);
}
}

String tableInfo = tableInfoJoiner.toString();
Expand Down

0 comments on commit fcde2a5

Please sign in to comment.