toma
March 12, 2018, 10:44am
1
What is the best way to get list of message fields that exist from a plugin in java?
jochen
(Jochen)
March 12, 2018, 11:15am
2
If you’re interested in the fields of a single message instance, you’d use Message#getFields()
or Message#getFieldsEntries()
:
public Map<String, Object> getFields() {
return ImmutableMap.copyOf(fields);
}
public Iterable<Map.Entry<String, Object>> getFieldsEntries() {
return Iterables.unmodifiableIterable(fields.entrySet());
}
If you’re interested in the fields of all messages in Elasticsearch matching a certain search query, you’d use Indices#getAllMessageFieldsForIndices()
or Indices#getAllMessageFields()
:
public Map<String, Set<String>> getAllMessageFieldsForIndices(final String[] writeIndexWildcards) {
final String indices = String.join(",", writeIndexWildcards);
final State request = new State.Builder()
.indices(indices)
.withMetadata()
.build();
final JestResult jestResult = JestUtils.execute(jestClient, request, () -> "Couldn't read cluster state for indices " + indices);
final JsonNode indicesJson = getClusterStateIndicesMetadata(jestResult.getJsonObject());
final ImmutableMap.Builder<String, Set<String>> fields = ImmutableMap.builder();
final Iterator<Map.Entry<String, JsonNode>> it = indicesJson.fields();
while (it.hasNext()) {
final Map.Entry<String, JsonNode> entry = it.next();
final String indexName = entry.getKey();
final Set<String> fieldNames = ImmutableSet.copyOf(
entry.getValue()
.path("mappings")
.path(IndexMapping.TYPE_MESSAGE)
.path("properties").fieldNames()
This file has been truncated. show original
1 Like
system
(system)
Closed
March 26, 2018, 11:15am
3
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.