本文整理汇总了Java中org.elasticsearch.index.get.GetResult类的典型用法代码示例。如果您正苦于以下问题:Java GetResult类的具体用法?Java GetResult怎么用?Java GetResult使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GetResult类属于org.elasticsearch.index.get包,在下文中一共展示了GetResult类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: testToAndFromXContent
import org.elasticsearch.index.get.GetResult; //导入依赖的package包/类
public void testToAndFromXContent() throws Exception {
XContentType xContentType = randomFrom(XContentType.values());
Tuple<GetResult, GetResult> tuple = randomGetResult(xContentType);
GetResponse getResponse = new GetResponse(tuple.v1());
GetResponse expectedGetResponse = new GetResponse(tuple.v2());
boolean humanReadable = randomBoolean();
BytesReference originalBytes = toXContent(getResponse, xContentType, humanReadable);
//test that we can parse what we print out
GetResponse parsedGetResponse;
try (XContentParser parser = createParser(xContentType.xContent(), originalBytes)) {
parsedGetResponse = GetResponse.fromXContent(parser);
assertNull(parser.nextToken());
}
assertEquals(expectedGetResponse, parsedGetResponse);
//print the parsed object out and test that the output is the same as the original output
BytesReference finalBytes = toXContent(parsedGetResponse, xContentType, humanReadable);
assertToXContentEquivalent(originalBytes, finalBytes, xContentType);
//check that the source stays unchanged, no shuffling of keys nor anything like that
assertEquals(expectedGetResponse.getSourceAsString(), parsedGetResponse.getSourceAsString());
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:21,代码来源:GetResponseTests.java
示例2: executeGet
import org.elasticsearch.index.get.GetResult; //导入依赖的package包/类
@Override
protected GetResponse executeGet(GetRequest getRequest) {
assertThat(getRequest.index(), Matchers.equalTo(indexedDocumentIndex));
assertThat(getRequest.type(), Matchers.equalTo(indexedDocumentType));
assertThat(getRequest.id(), Matchers.equalTo(indexedDocumentId));
assertThat(getRequest.routing(), Matchers.equalTo(indexedDocumentRouting));
assertThat(getRequest.preference(), Matchers.equalTo(indexedDocumentPreference));
assertThat(getRequest.version(), Matchers.equalTo(indexedDocumentVersion));
if (indexedDocumentExists) {
return new GetResponse(
new GetResult(indexedDocumentIndex, indexedDocumentType, indexedDocumentId, 0L, true, documentSource,
Collections.emptyMap())
);
} else {
return new GetResponse(
new GetResult(indexedDocumentIndex, indexedDocumentType, indexedDocumentId, -1, false, null, Collections.emptyMap())
);
}
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:20,代码来源:PercolateQueryBuilderTests.java
示例3: executeGet
import org.elasticsearch.index.get.GetResult; //导入依赖的package包/类
@Override
protected GetResponse executeGet(GetRequest getRequest) {
assertThat(indexedShapeToReturn, notNullValue());
assertThat(indexedShapeId, notNullValue());
assertThat(indexedShapeType, notNullValue());
assertThat(getRequest.id(), equalTo(indexedShapeId));
assertThat(getRequest.type(), equalTo(indexedShapeType));
String expectedShapeIndex = indexedShapeIndex == null ? GeoShapeQueryBuilder.DEFAULT_SHAPE_INDEX_NAME : indexedShapeIndex;
assertThat(getRequest.index(), equalTo(expectedShapeIndex));
String expectedShapePath = indexedShapePath == null ? GeoShapeQueryBuilder.DEFAULT_SHAPE_FIELD_NAME : indexedShapePath;
String json;
try {
XContentBuilder builder = XContentFactory.jsonBuilder().prettyPrint();
builder.startObject();
builder.field(expectedShapePath, indexedShapeToReturn);
builder.endObject();
json = builder.string();
} catch (IOException ex) {
throw new ElasticsearchException("boom", ex);
}
return new GetResponse(new GetResult(indexedShapeIndex, indexedShapeType, indexedShapeId, 0, true, new BytesArray(json), null));
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:23,代码来源:GeoShapeQueryBuilderTests.java
示例4: testToString
import org.elasticsearch.index.get.GetResult; //导入依赖的package包/类
public void testToString() {
GetResponse getResponse = new GetResponse(
new GetResult("index", "type", "id", 1, true, new BytesArray("{ \"field1\" : " + "\"value1\", \"field2\":\"value2\"}"),
Collections.singletonMap("field1", new GetField("field1", Collections.singletonList("value1")))));
assertEquals("{\"_index\":\"index\",\"_type\":\"type\",\"_id\":\"id\",\"_version\":1,\"found\":true,\"_source\":{ \"field1\" "
+ ": \"value1\", \"field2\":\"value2\"},\"fields\":{\"field1\":[\"value1\"]}}", getResponse.toString());
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:8,代码来源:GetResponseTests.java
示例5: build
import org.elasticsearch.index.get.GetResult; //导入依赖的package包/类
public GetResult build() {
// Check for .kibana.* in the source
BytesReference replacedContent = null;
if (response != null && !response.isSourceEmpty() && replacedIndex != null && index != null) {
String source = response.getSourceAsBytesRef().toUtf8();
String replaced = source.replaceAll(replacedIndex, index);
replacedContent = new BytesArray(replaced);
}
// Check for .kibana.* in the fields
for (String key : responseFields.keySet()) {
GetField replacedField = responseFields.get(key);
for (Object o : replacedField.getValues()) {
if (o instanceof String) {
String value = (String) o;
if (value.contains(replacedIndex)) {
replacedField.getValues().remove(o);
replacedField.getValues().add(value.replaceAll(replacedIndex, index));
}
}
}
}
GetResult result = new GetResult(index, type, id, version, exists, replacedContent, responseFields);
LOG.debug("Built GetResult: {}", result);
return result;
}
开发者ID:fabric8io,项目名称:openshift-elasticsearch-plugin,代码行数:30,代码来源:GetResultBuilder.java
示例6: testBuildWhenResponseFieldsAreNotNull
import org.elasticsearch.index.get.GetResult; //导入依赖的package包/类
@Test
public void testBuildWhenResponseFieldsAreNotNull() {
Object [] values = new String [] {"bar"};
GetField field = new GetField("aField", new ArrayList<Object>(Arrays.asList(values)));
Map<String, GetField> fields = new HashMap<>();
fields.put("aField", field);
when(response.getFields()).thenReturn(fields );
when(response.isSourceEmpty()).thenReturn(true);
givenAnInitializedBuilder();
GetResult result = builder.build();
assertNotNull(result);
}
开发者ID:fabric8io,项目名称:openshift-elasticsearch-plugin,代码行数:14,代码来源:GetResultBuilderTest.java
示例7: doGetFromSearchRequest
import org.elasticsearch.index.get.GetResult; //导入依赖的package包/类
protected void doGetFromSearchRequest(final GetRequest getRequest, final SearchRequest searchRequest, final ActionListener listener, final Client client) {
client.search(searchRequest, new DelegatingActionListener<SearchResponse, GetResponse>(listener) {
@Override
public GetResponse getDelegatedFromInstigator(final SearchResponse searchResponse) {
if (searchResponse.getHits().getTotalHits() <= 0) {
return new GetResponse(new GetResult(getRequest.index(), getRequest.type(), getRequest.id(), getRequest.version(), false, null,
null));
} else if (searchResponse.getHits().getTotalHits() > 1) {
throw new RuntimeException("cannot happen");
} else {
final SearchHit sh = searchResponse.getHits().getHits()[0];
return new GetResponse(new GetResult(sh.index(), sh.type(), sh.id(), sh.version(), true, sh.getSourceRef(), null));
}
}
});
}
开发者ID:petalmd,项目名称:armor,代码行数:19,代码来源:AbstractActionFilter.java
示例8: toXContent
import org.elasticsearch.index.get.GetResult; //导入依赖的package包/类
@Override
protected XContentBuilder toXContent(ExplainRequest request, ExplainResponse response, XContentBuilder builder) throws IOException {
builder.startObject();
builder.field(Fields.OK, response.isExists())
.field(Fields._INDEX, request.index())
.field(Fields._TYPE, request.type())
.field(Fields._ID, request.id())
.field(Fields.MATCHED, response.isMatch());
if (response.hasExplanation()) {
builder.startObject(Fields.EXPLANATION);
buildExplanation(builder, response.getExplanation());
builder.endObject();
}
GetResult getResult = response.getGetResult();
if (getResult != null) {
builder.startObject(Fields.GET);
getResult.toXContentEmbedded(builder, ToXContent.EMPTY_PARAMS);
builder.endObject();
}
builder.endObject();
return builder;
}
开发者ID:javanna,项目名称:elasticshell,代码行数:24,代码来源:ExplainRequestBuilder.java
示例9: addGeneratedTermVectors
import org.elasticsearch.index.get.GetResult; //导入依赖的package包/类
private static Fields addGeneratedTermVectors(IndexShard indexShard, Engine.GetResult get, Fields termVectorsByField, TermVectorsRequest request, Set<String> selectedFields) throws IOException {
/* only keep valid fields */
Set<String> validFields = new HashSet<>();
for (String field : selectedFields) {
MappedFieldType fieldType = indexShard.mapperService().fullName(field);
if (!isValidField(fieldType)) {
continue;
}
// already retrieved, only if the analyzer hasn't been overridden at the field
if (fieldType.storeTermVectors() &&
(request.perFieldAnalyzer() == null || !request.perFieldAnalyzer().containsKey(field))) {
continue;
}
validFields.add(field);
}
if (validFields.isEmpty()) {
return termVectorsByField;
}
/* generate term vectors from fetched document fields */
String[] getFields = validFields.toArray(new String[validFields.size() + 1]);
getFields[getFields.length - 1] = SourceFieldMapper.NAME;
GetResult getResult = indexShard.getService().get(
get, request.id(), request.type(), getFields, null);
Fields generatedTermVectors = generateTermVectors(indexShard, getResult.sourceAsMap(), getResult.getFields().values(), request.offsets(), request.perFieldAnalyzer(), validFields);
/* merge with existing Fields */
if (termVectorsByField == null) {
return generatedTermVectors;
} else {
return mergeFields(termVectorsByField, generatedTermVectors);
}
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:35,代码来源:TermVectorsService.java
示例10: readFrom
import org.elasticsearch.index.get.GetResult; //导入依赖的package包/类
@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
index = in.readString();
type = in.readString();
id = in.readString();
exists = in.readBoolean();
if (in.readBoolean()) {
explanation = readExplanation(in);
}
if (in.readBoolean()) {
getResult = GetResult.readGetResult(in);
}
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:15,代码来源:ExplainResponse.java
示例11: shardOperation
import org.elasticsearch.index.get.GetResult; //导入依赖的package包/类
@Override
protected ExplainResponse shardOperation(ExplainRequest request, ShardId shardId) throws IOException {
ShardSearchLocalRequest shardSearchLocalRequest = new ShardSearchLocalRequest(shardId,
new String[]{request.type()}, request.nowInMillis, request.filteringAlias());
SearchContext context = searchService.createSearchContext(shardSearchLocalRequest, SearchService.NO_TIMEOUT, null);
Term uidTerm = new Term(UidFieldMapper.NAME, Uid.createUidAsBytes(request.type(), request.id()));
Engine.GetResult result = null;
try {
result = context.indexShard().get(new Engine.Get(false, uidTerm));
if (!result.exists()) {
return new ExplainResponse(shardId.getIndexName(), request.type(), request.id(), false);
}
context.parsedQuery(context.getQueryShardContext().toQuery(request.query()));
context.preProcess(true);
int topLevelDocId = result.docIdAndVersion().docId + result.docIdAndVersion().context.docBase;
Explanation explanation = context.searcher().explain(context.query(), topLevelDocId);
for (RescoreSearchContext ctx : context.rescore()) {
Rescorer rescorer = ctx.rescorer();
explanation = rescorer.explain(topLevelDocId, context, ctx, explanation);
}
if (request.storedFields() != null || (request.fetchSourceContext() != null && request.fetchSourceContext().fetchSource())) {
// Advantage is that we're not opening a second searcher to retrieve the _source. Also
// because we are working in the same searcher in engineGetResult we can be sure that a
// doc isn't deleted between the initial get and this call.
GetResult getResult = context.indexShard().getService().get(result, request.id(), request.type(), request.storedFields(), request.fetchSourceContext());
return new ExplainResponse(shardId.getIndexName(), request.type(), request.id(), true, explanation, getResult);
} else {
return new ExplainResponse(shardId.getIndexName(), request.type(), request.id(), true, explanation);
}
} catch (IOException e) {
throw new ElasticsearchException("Could not explain", e);
} finally {
Releasables.close(result, context);
}
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:36,代码来源:TransportExplainAction.java
示例12: shardOperation
import org.elasticsearch.index.get.GetResult; //导入依赖的package包/类
@Override
protected MultiGetShardResponse shardOperation(MultiGetShardRequest request, ShardId shardId) {
IndexService indexService = indicesService.indexServiceSafe(shardId.getIndex());
IndexShard indexShard = indexService.getShard(shardId.id());
if (request.refresh() && !request.realtime()) {
indexShard.refresh("refresh_flag_mget");
}
MultiGetShardResponse response = new MultiGetShardResponse();
for (int i = 0; i < request.locations.size(); i++) {
MultiGetRequest.Item item = request.items.get(i);
try {
GetResult getResult = indexShard.getService().get(item.type(), item.id(), item.storedFields(), request.realtime(), item.version(),
item.versionType(), item.fetchSourceContext());
response.add(request.locations.get(i), new GetResponse(getResult));
} catch (Exception e) {
if (TransportActions.isShardNotAvailableException(e)) {
throw (ElasticsearchException) e;
} else {
logger.debug((Supplier<?>) () -> new ParameterizedMessage("{} failed to execute multi_get for [{}]/[{}]", shardId,
item.type(), item.id()), e);
response.add(request.locations.get(i), new MultiGetResponse.Failure(request.index(), item.type(), item.id(), e));
}
}
}
return response;
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:30,代码来源:TransportShardMultiGetAction.java
示例13: shardOperation
import org.elasticsearch.index.get.GetResult; //导入依赖的package包/类
@Override
protected GetResponse shardOperation(GetRequest request, ShardId shardId) {
IndexService indexService = indicesService.indexServiceSafe(shardId.getIndex());
IndexShard indexShard = indexService.getShard(shardId.id());
if (request.refresh() && !request.realtime()) {
indexShard.refresh("refresh_flag_get");
}
GetResult result = indexShard.getService().get(request.type(), request.id(), request.storedFields(),
request.realtime(), request.version(), request.versionType(), request.fetchSourceContext());
return new GetResponse(result);
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:14,代码来源:TransportGetAction.java
示例14: readFrom
import org.elasticsearch.index.get.GetResult; //导入依赖的package包/类
@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
if (in.readBoolean()) {
getResult = GetResult.readGetResult(in);
}
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:8,代码来源:UpdateResponse.java
示例15: parseXContentFields
import org.elasticsearch.index.get.GetResult; //导入依赖的package包/类
/**
* Parse the current token and update the parsing context appropriately.
*/
public static void parseXContentFields(XContentParser parser, Builder context) throws IOException {
XContentParser.Token token = parser.currentToken();
String currentFieldName = parser.currentName();
if (GET.equals(currentFieldName)) {
if (token == XContentParser.Token.START_OBJECT) {
context.setGetResult(GetResult.fromXContentEmbedded(parser));
}
} else {
DocWriteResponse.parseInnerToXContent(parser, context);
}
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:16,代码来源:UpdateResponse.java
示例16: build
import org.elasticsearch.index.get.GetResult; //导入依赖的package包/类
@Override
public UpdateResponse build() {
UpdateResponse update;
if (shardInfo != null && seqNo != null) {
update = new UpdateResponse(shardInfo, shardId, type, id, seqNo, version, result);
} else {
update = new UpdateResponse(shardId, type, id, version, result);
}
if (getResult != null) {
update.setGetResult(new GetResult(update.getIndex(), update.getType(), update.getId(), update.getVersion(),
getResult.isExists(),getResult.internalSourceRef(), getResult.getFields()));
}
update.setForcedRefresh(forcedRefresh);
return update;
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:16,代码来源:UpdateResponse.java
示例17: prepare
import org.elasticsearch.index.get.GetResult; //导入依赖的package包/类
/**
* Prepares an update request by converting it into an index or delete request or an update response (no action).
*/
public Result prepare(UpdateRequest request, IndexShard indexShard, LongSupplier nowInMillis) {
final GetResult getResult = indexShard.getService().get(request.type(), request.id(),
new String[]{RoutingFieldMapper.NAME, ParentFieldMapper.NAME},
true, request.version(), request.versionType(), FetchSourceContext.FETCH_SOURCE);
return prepare(indexShard.shardId(), request, getResult, nowInMillis);
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:10,代码来源:UpdateHelper.java
示例18: executeGet
import org.elasticsearch.index.get.GetResult; //导入依赖的package包/类
@Override
public GetResponse executeGet(GetRequest getRequest) {
String json;
try {
XContentBuilder builder = XContentFactory.jsonBuilder().prettyPrint();
builder.startObject();
builder.array(termsPath, randomTerms.toArray(new Object[randomTerms.size()]));
builder.endObject();
json = builder.string();
} catch (IOException ex) {
throw new ElasticsearchException("boom", ex);
}
return new GetResponse(new GetResult(getRequest.index(), getRequest.type(), getRequest.id(), 0, true, new BytesArray(json), null));
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:15,代码来源:TermsQueryBuilderTests.java
示例19: processGeneratedColumns
import org.elasticsearch.index.get.GetResult; //导入依赖的package包/类
private void processGeneratedColumns(final DocTableInfo tableInfo,
Map<String, Object> updatedColumns,
Map<String, Object> updatedGeneratedColumns,
boolean validateExpressionValue,
@Nullable GetResult getResult) {
SymbolToFieldExtractorContext ctx = new SymbolToFieldExtractorContext(functions, updatedColumns);
for (GeneratedReferenceInfo referenceInfo : tableInfo.generatedColumns()) {
// partitionedBy columns cannot be updated
if (!tableInfo.partitionedByColumns().contains(referenceInfo)) {
Object givenValue = updatedGeneratedColumns.get(referenceInfo.ident().columnIdent().fqn());
if ((givenValue != null && validateExpressionValue)
||
generatedExpressionEvaluationNeeded(referenceInfo.referencedReferenceInfos(), updatedColumns.keySet())) {
// at least one referenced column was updated, need to evaluate expression and update column
Function<GetResult, Object> extractor = SYMBOL_TO_FIELD_EXTRACTOR.convert(referenceInfo.generatedExpression(), ctx);
Object value = extractor.apply(getResult);
if (givenValue == null) {
// add column & value
updatedColumns.put(referenceInfo.ident().columnIdent().fqn(), value);
} else if (validateExpressionValue && referenceInfo.type().compareValueTo(value, givenValue) != 0) {
throw new IllegalArgumentException(String.format(Locale.ENGLISH,
"Given value %s for generated column does not match defined generated expression value %s",
givenValue, value));
}
}
}
}
}
开发者ID:baidu,项目名称:Elasticsearch,代码行数:30,代码来源:TransportShardUpsertAction.java
示例20: build
import org.elasticsearch.index.get.GetResult; //导入依赖的package包/类
@Override
public Function<GetResult, Object> build(final Reference reference, SymbolToFieldExtractor.Context context) {
return new Function<GetResult, Object>() {
@Override
public Object apply(GetResult getResult) {
if (getResult == null) {
return null;
}
return reference.valueType().value(XContentMapValues.extractValue(
reference.info().ident().columnIdent().fqn(), getResult.sourceAsMap()));
}
};
}
开发者ID:baidu,项目名称:Elasticsearch,代码行数:14,代码来源:TransportShardUpsertAction.java
注:本文中的org.elasticsearch.index.get.GetResult类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论