本文整理汇总了Java中org.elasticsearch.common.xcontent.XContentHelper.convertToMap方法的典型用法代码示例。如果您正苦于以下问题:Java XContentHelper.convertToMap方法的具体用法?Java XContentHelper.convertToMap怎么用?Java XContentHelper.convertToMap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.elasticsearch.common.xcontent.XContentHelper
的用法示例。
在下文中一共展示了XContentHelper.convertToMap方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute
import org.elasticsearch.common.xcontent.XContentHelper; //导入方法依赖的package包/类
@Override
public void execute(IngestDocument document) throws Exception {
String stringValue = document.getFieldValue(field, String.class);
try {
Map<String, Object> mapValue = XContentHelper.convertToMap(JsonXContent.jsonXContent, stringValue, false);
if (addToRoot) {
for (Map.Entry<String, Object> entry : mapValue.entrySet()) {
document.setFieldValue(entry.getKey(), entry.getValue());
}
} else {
document.setFieldValue(targetField, mapValue);
}
} catch (ElasticsearchParseException e) {
throw new IllegalArgumentException(e);
}
}
示例2: testIncludingObjectWithNestedIncludedObject
import org.elasticsearch.common.xcontent.XContentHelper; //导入方法依赖的package包/类
@SuppressWarnings({"unchecked"})
public void testIncludingObjectWithNestedIncludedObject() throws Exception {
XContentBuilder builder = XContentFactory.jsonBuilder().startObject()
.startObject("obj1")
.startObject("obj2")
.endObject()
.endObject()
.endObject();
Tuple<XContentType, Map<String, Object>> mapTuple = XContentHelper.convertToMap(builder.bytes(), true, builder.contentType());
Map<String, Object> filteredSource = XContentMapValues.filter(mapTuple.v2(), new String[]{"*.obj2"}, Strings.EMPTY_ARRAY);
assertThat(filteredSource.size(), equalTo(1));
assertThat(filteredSource, hasKey("obj1"));
assertThat(((Map) filteredSource.get("obj1")).size(), equalTo(1));
assertThat(((Map<String, Object>) filteredSource.get("obj1")), hasKey("obj2"));
assertThat(((Map) ((Map) filteredSource.get("obj1")).get("obj2")).size(), equalTo(0));
}
示例3: parseCreateField
import org.elasticsearch.common.xcontent.XContentHelper; //导入方法依赖的package包/类
@Override
protected void parseCreateField(ParseContext context, List<IndexableField> fields) throws IOException {
if (!enabled) {
return;
}
if (!fieldType().stored()) {
return;
}
BytesReference source = context.sourceToParse().source();
// Percolate and tv APIs may not set the source and that is ok, because these APIs will not index any data
if (source == null) {
return;
}
if (filter != null) {
// we don't update the context source if we filter, we want to keep it as is...
Tuple<XContentType, Map<String, Object>> mapTuple =
XContentHelper.convertToMap(source, true, context.sourceToParse().getXContentType());
Map<String, Object> filteredSource = filter.apply(mapTuple.v2());
BytesStreamOutput bStream = new BytesStreamOutput();
XContentType contentType = mapTuple.v1();
XContentBuilder builder = XContentFactory.contentBuilder(contentType, bStream).map(filteredSource);
builder.close();
source = bStream.bytes();
}
BytesRef ref = source.toBytesRef();
fields.add(new StoredField(fieldType().name(), ref.bytes, ref.offset, ref.length));
}
示例4: validateAliasStandalone
import org.elasticsearch.common.xcontent.XContentHelper; //导入方法依赖的package包/类
/**
* Allows to partially validate an alias, without knowing which index it'll get applied to.
* Useful with index templates containing aliases. Checks also that it is possible to parse
* the alias filter via {@link org.elasticsearch.common.xcontent.XContentParser},
* without validating it as a filter though.
* @throws IllegalArgumentException if the alias is not valid
*/
public void validateAliasStandalone(Alias alias) {
validateAliasStandalone(alias.name(), alias.indexRouting());
if (Strings.hasLength(alias.filter())) {
try {
XContentHelper.convertToMap(XContentFactory.xContent(alias.filter()), alias.filter(), false);
} catch (Exception e) {
throw new IllegalArgumentException("failed to parse filter for alias [" + alias.name() + "]", e);
}
}
}
示例5: testThatFilterIncludesEmptyObjectWhenUsingIncludes
import org.elasticsearch.common.xcontent.XContentHelper; //导入方法依赖的package包/类
public void testThatFilterIncludesEmptyObjectWhenUsingIncludes() throws Exception {
XContentBuilder builder = XContentFactory.jsonBuilder().startObject()
.startObject("obj")
.endObject()
.endObject();
Tuple<XContentType, Map<String, Object>> mapTuple = XContentHelper.convertToMap(builder.bytes(), true, builder.contentType());
Map<String, Object> filteredSource = XContentMapValues.filter(mapTuple.v2(), new String[]{"obj"}, Strings.EMPTY_ARRAY);
assertThat(mapTuple.v2(), equalTo(filteredSource));
}
示例6: testThatFilterIncludesEmptyObjectWhenUsingExcludes
import org.elasticsearch.common.xcontent.XContentHelper; //导入方法依赖的package包/类
public void testThatFilterIncludesEmptyObjectWhenUsingExcludes() throws Exception {
XContentBuilder builder = XContentFactory.jsonBuilder().startObject()
.startObject("obj")
.endObject()
.endObject();
Tuple<XContentType, Map<String, Object>> mapTuple = XContentHelper.convertToMap(builder.bytes(), true, builder.contentType());
Map<String, Object> filteredSource = XContentMapValues.filter(mapTuple.v2(), Strings.EMPTY_ARRAY, new String[]{"nonExistingField"});
assertThat(mapTuple.v2(), equalTo(filteredSource));
}
示例7: testNotOmittingObjectsWithExcludedProperties
import org.elasticsearch.common.xcontent.XContentHelper; //导入方法依赖的package包/类
public void testNotOmittingObjectsWithExcludedProperties() throws Exception {
XContentBuilder builder = XContentFactory.jsonBuilder().startObject()
.startObject("obj")
.field("f1", "v1")
.endObject()
.endObject();
Tuple<XContentType, Map<String, Object>> mapTuple = XContentHelper.convertToMap(builder.bytes(), true, builder.contentType());
Map<String, Object> filteredSource = XContentMapValues.filter(mapTuple.v2(), Strings.EMPTY_ARRAY, new String[]{"obj.f1"});
assertThat(filteredSource.size(), equalTo(1));
assertThat(filteredSource, hasKey("obj"));
assertThat(((Map) filteredSource.get("obj")).size(), equalTo(0));
}
示例8: testNotOmittingObjectWithNestedExcludedObject
import org.elasticsearch.common.xcontent.XContentHelper; //导入方法依赖的package包/类
@SuppressWarnings({"unchecked"})
public void testNotOmittingObjectWithNestedExcludedObject() throws Exception {
XContentBuilder builder = XContentFactory.jsonBuilder().startObject()
.startObject("obj1")
.startObject("obj2")
.startObject("obj3")
.endObject()
.endObject()
.endObject()
.endObject();
// implicit include
Tuple<XContentType, Map<String, Object>> mapTuple = XContentHelper.convertToMap(builder.bytes(), true, builder.contentType());
Map<String, Object> filteredSource = XContentMapValues.filter(mapTuple.v2(), Strings.EMPTY_ARRAY, new String[]{"*.obj2"});
assertThat(filteredSource.size(), equalTo(1));
assertThat(filteredSource, hasKey("obj1"));
assertThat(((Map) filteredSource.get("obj1")).size(), equalTo(0));
// explicit include
filteredSource = XContentMapValues.filter(mapTuple.v2(), new String[]{"obj1"}, new String[]{"*.obj2"});
assertThat(filteredSource.size(), equalTo(1));
assertThat(filteredSource, hasKey("obj1"));
assertThat(((Map) filteredSource.get("obj1")).size(), equalTo(0));
// wild card include
filteredSource = XContentMapValues.filter(mapTuple.v2(), new String[]{"*.obj2"}, new String[]{"*.obj3"});
assertThat(filteredSource.size(), equalTo(1));
assertThat(filteredSource, hasKey("obj1"));
assertThat(((Map<String, Object>) filteredSource.get("obj1")), hasKey("obj2"));
assertThat(((Map) ((Map) filteredSource.get("obj1")).get("obj2")).size(), equalTo(0));
}
示例9: sourceAsMapAndType
import org.elasticsearch.common.xcontent.XContentHelper; //导入方法依赖的package包/类
public static Tuple<XContentType, Map<String, Object>> sourceAsMapAndType(BytesReference source) throws ElasticsearchParseException {
return XContentHelper.convertToMap(source, false);
}
示例10: prepareUpdate
import org.elasticsearch.common.xcontent.XContentHelper; //导入方法依赖的package包/类
/**
* Prepares an update request by converting it into an index request.
* <p/>
* TODO: detect a NOOP and return an update response if true
*/
@SuppressWarnings("unchecked")
private SourceAndVersion prepareUpdate(DocTableInfo tableInfo,
ShardUpsertRequest request,
ShardUpsertRequest.Item item,
IndexShard indexShard) throws ElasticsearchException {
final GetResult getResult = indexShard.getService().get(request.type(), item.id(),
new String[]{RoutingFieldMapper.NAME, ParentFieldMapper.NAME, TTLFieldMapper.NAME},
true, Versions.MATCH_ANY, VersionType.INTERNAL, FetchSourceContext.FETCH_SOURCE, false);
if (!getResult.isExists()) {
throw new DocumentMissingException(new ShardId(request.index(), request.shardId().id()), request.type(), item.id());
}
if (getResult.internalSourceRef() == null) {
// no source, we can't do nothing, through a failure...
throw new DocumentSourceMissingException(new ShardId(request.index(), request.shardId().id()), request.type(), item.id());
}
if (item.version() != Versions.MATCH_ANY && item.version() != getResult.getVersion()) {
throw new VersionConflictEngineException(
indexShard.shardId(), Constants.DEFAULT_MAPPING_TYPE, item.id(), getResult.getVersion(), item.version());
}
Tuple<XContentType, Map<String, Object>> sourceAndContent = XContentHelper.convertToMap(getResult.internalSourceRef(), true);
final Map<String, Object> updatedSourceAsMap;
final XContentType updateSourceContentType = sourceAndContent.v1();
updatedSourceAsMap = sourceAndContent.v2();
SymbolToFieldExtractorContext ctx = new SymbolToFieldExtractorContext(functions, item.insertValues());
Map<String, Object> pathsToUpdate = new LinkedHashMap<>();
Map<String, Object> updatedGeneratedColumns = new LinkedHashMap<>();
for (int i = 0; i < request.updateColumns().length; i++) {
/**
* NOTE: mapping isn't applied. So if an Insert was done using the ES Rest Endpoint
* the data might be returned in the wrong format (date as string instead of long)
*/
String columnPath = request.updateColumns()[i];
Object value = SYMBOL_TO_FIELD_EXTRACTOR.convert(item.updateAssignments()[i], ctx).apply(getResult);
ReferenceInfo referenceInfo = tableInfo.getReferenceInfo(ColumnIdent.fromPath(columnPath));
if (referenceInfo instanceof GeneratedReferenceInfo) {
updatedGeneratedColumns.put(columnPath, value);
} else {
pathsToUpdate.put(columnPath, value);
}
}
processGeneratedColumns(tableInfo, pathsToUpdate, updatedGeneratedColumns, request.validateGeneratedColumns(), getResult);
updateSourceByPaths(updatedSourceAsMap, pathsToUpdate);
try {
XContentBuilder builder = XContentFactory.contentBuilder(updateSourceContentType);
builder.map(updatedSourceAsMap);
return new SourceAndVersion(builder.bytes(), getResult.getVersion());
} catch (IOException e) {
throw new ElasticsearchGenerationException("Failed to generate [" + updatedSourceAsMap + "]", e);
}
}