use of org.elasticsearch.common.collect.MapBuilder in project elasticsearch by elastic.
the class TransportGetFieldMappingsIndexAction method findFieldMappingsByType.
private Map<String, FieldMappingMetaData> findFieldMappingsByType(DocumentMapper documentMapper, GetFieldMappingsIndexRequest request) {
MapBuilder<String, FieldMappingMetaData> fieldMappings = new MapBuilder<>();
final DocumentFieldMappers allFieldMappers = documentMapper.mappers();
for (String field : request.fields()) {
if (Regex.isMatchAllPattern(field)) {
for (FieldMapper fieldMapper : allFieldMappers) {
addFieldMapper(fieldMapper.fieldType().name(), fieldMapper, fieldMappings, request.includeDefaults());
}
} else if (Regex.isSimpleMatchPattern(field)) {
for (FieldMapper fieldMapper : allFieldMappers) {
if (Regex.simpleMatch(field, fieldMapper.fieldType().name())) {
addFieldMapper(fieldMapper.fieldType().name(), fieldMapper, fieldMappings, request.includeDefaults());
}
}
} else {
// not a pattern
FieldMapper fieldMapper = allFieldMappers.smartNameFieldMapper(field);
if (fieldMapper != null) {
addFieldMapper(field, fieldMapper, fieldMappings, request.includeDefaults());
} else if (request.probablySingleFieldRequest()) {
fieldMappings.put(field, FieldMappingMetaData.NULL);
}
}
}
return fieldMappings.immutableMap();
}
use of org.elasticsearch.common.collect.MapBuilder in project crate by crate.
the class TransportShardUpsertActionTest method testGeneratedColumnsValidationWorksForArrayColumns.
@Test
public void testGeneratedColumnsValidationWorksForArrayColumns() throws Exception {
// test no exception are thrown when validating array generated columns
Map<String, Object> updatedColumns = MapBuilder.<String, Object>newMapBuilder().put("obj", MapBuilder.<String, Object>newMapBuilder().put("arr", new Object[] { 1 }).map()).map();
Map<String, Object> updatedGeneratedColumns = MapBuilder.<String, Object>newMapBuilder().put("arr", new Object[] { 1 }).map();
DocTableInfo docTableInfo = new TestingTableInfo.Builder(new TableIdent(null, "generated_column"), new Routing(Collections.<String, Map<String, List<Integer>>>emptyMap())).add("obj", DataTypes.OBJECT, null).add("obj", new ArrayType(DataTypes.INTEGER), Arrays.asList("arr")).addGeneratedColumn("arr", new ArrayType(DataTypes.INTEGER), "obj['arr']", false).build(getFunctions());
transportShardUpsertAction.processGeneratedColumns(docTableInfo, updatedColumns, updatedGeneratedColumns, false);
}
use of org.elasticsearch.common.collect.MapBuilder in project bboss-elastic by bbossgroups.
the class ElasticSearchLogStashEventSerializer method appendHeaders.
private void appendHeaders(XContentBuilder builder, Event event) throws IOException {
// Map<String, String> headers = Maps.newHashMap(event.getHeaders());
MapBuilder mapBuilder = MapBuilder.newMapBuilder();
// mapBuilder.putAll(event.getHeaders());
// Map<String, String> headers = mapBuilder.map();
Map<String, String> headers = event.getHeaders();
if (headers == null || headers.size() == 0) {
return;
}
String timestamp = headers.remove("timestamp");
if (!SimpleStringUtil.isEmpty(timestamp) && SimpleStringUtil.isEmpty(headers.get("@timestamp"))) {
long timestampMs = Long.parseLong(timestamp);
builder.field("@timestamp", new Date(timestampMs));
}
String source = headers.remove("source");
if (!SimpleStringUtil.isEmpty(source) && SimpleStringUtil.isEmpty(headers.get("@source"))) {
ContentBuilderUtil.appendField(builder, "@source", source.getBytes(charset));
}
String type = headers.remove("type");
if (!SimpleStringUtil.isEmpty(type) && SimpleStringUtil.isEmpty(headers.get("@type"))) {
ContentBuilderUtil.appendField(builder, "@type", type.getBytes(charset));
}
String host = headers.remove("host");
if (!SimpleStringUtil.isEmpty(host) && SimpleStringUtil.isEmpty(headers.get("@source_host"))) {
ContentBuilderUtil.appendField(builder, "@source_host", host.getBytes(charset));
}
String srcPath = headers.remove("src_path");
if (!SimpleStringUtil.isEmpty(srcPath) && SimpleStringUtil.isEmpty(headers.get("@source_path"))) {
ContentBuilderUtil.appendField(builder, "@source_path", srcPath.getBytes(charset));
}
builder.startObject("@fields");
for (String key : headers.keySet()) {
byte[] val = headers.get(key).getBytes(charset);
ContentBuilderUtil.appendField(builder, key, val);
}
builder.endObject();
}
use of org.elasticsearch.common.collect.MapBuilder in project elasticsearch by elastic.
the class TransportGetFieldMappingsIndexAction method shardOperation.
@Override
protected GetFieldMappingsResponse shardOperation(final GetFieldMappingsIndexRequest request, ShardId shardId) {
assert shardId != null;
IndexService indexService = indicesService.indexServiceSafe(shardId.getIndex());
Collection<String> typeIntersection;
if (request.types().length == 0) {
typeIntersection = indexService.mapperService().types();
} else {
typeIntersection = indexService.mapperService().types().stream().filter(type -> Regex.simpleMatch(request.types(), type)).collect(Collectors.toCollection(ArrayList::new));
if (typeIntersection.isEmpty()) {
throw new TypeMissingException(shardId.getIndex(), request.types());
}
}
MapBuilder<String, Map<String, FieldMappingMetaData>> typeMappings = new MapBuilder<>();
for (String type : typeIntersection) {
DocumentMapper documentMapper = indexService.mapperService().documentMapper(type);
Map<String, FieldMappingMetaData> fieldMapping = findFieldMappingsByType(documentMapper, request);
if (!fieldMapping.isEmpty()) {
typeMappings.put(type, fieldMapping);
}
}
return new GetFieldMappingsResponse(singletonMap(shardId.getIndexName(), typeMappings.immutableMap()));
}
use of org.elasticsearch.common.collect.MapBuilder in project bboss-elastic by bbossgroups.
the class ElasticSearchJSONEventSerializer method appendHeaders.
private void appendHeaders(Map<String, Object> builder, Event event) throws IOException {
// Map<String, String> headers = Maps.newHashMap(event.getHeaders());
MapBuilder mapBuilder = MapBuilder.newMapBuilder();
// mapBuilder.putAll(event.getHeaders());
// Map<String, String> headers = mapBuilder.map();
Map<String, String> headers = event.getHeaders();
if (headers == null || headers.size() == 0) {
return;
}
String timestamp = headers.remove("timestamp");
if (!SimpleStringUtil.isEmpty(timestamp) && SimpleStringUtil.isEmpty(headers.get("@timestamp"))) {
long timestampMs = Long.parseLong(timestamp);
builder.put("@timestamp", new Date(timestampMs));
}
String source = headers.remove("source");
if (!SimpleStringUtil.isEmpty(source) && SimpleStringUtil.isEmpty(headers.get("@source"))) {
builder.put("@source", source);
}
String type = headers.remove("type");
if (!SimpleStringUtil.isEmpty(type) && SimpleStringUtil.isEmpty(headers.get("@type"))) {
builder.put("@type", type);
}
String host = headers.remove("host");
if (!SimpleStringUtil.isEmpty(host) && SimpleStringUtil.isEmpty(headers.get("@source_host"))) {
builder.put("beat.host", host);
}
String srcPath = headers.remove("src_path");
if (!SimpleStringUtil.isEmpty(srcPath) && SimpleStringUtil.isEmpty(headers.get("@source_path"))) {
builder.put("@source_path", srcPath);
}
for (String key : headers.keySet()) {
String val = headers.get(key);
builder.put(key, val);
}
}
Aggregations