当前位置: 首页>>代码示例>>Java>>正文


Java GetResponse类代码示例

本文整理汇总了Java中org.elasticsearch.action.get.GetResponse的典型用法代码示例。如果您正苦于以下问题:Java GetResponse类的具体用法?Java GetResponse怎么用?Java GetResponse使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


GetResponse类属于org.elasticsearch.action.get包,在下文中一共展示了GetResponse类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: upsertProduct

import org.elasticsearch.action.get.GetResponse; //导入依赖的package包/类
@Test
public void upsertProduct() throws Exception {
  Product product = Product.newBuilder()
      .setProductId(faker.number().randomNumber())
      .setProductName(faker.company().name())
      .setProductPrice(faker.number().randomDouble(2, 10, 100))
      .setProductStatus(ProductStatus.InStock)
      .build();
  productDao.upsertProduct(product);
  esClient.admin().indices().flush(Requests.flushRequest(INDEX)).actionGet();

  GetResponse getResponse = esClient.prepareGet(INDEX, TYPE, String.valueOf(product.getProductId())).get();
  JsonFormat.Parser jsonParser = injector.getInstance(JsonFormat.Parser.class);
  Product.Builder builder = Product.newBuilder();
  jsonParser.merge(getResponse.getSourceAsString(), builder);
  assertThat(builder.build()).isEqualTo(product);
}
 
开发者ID:email2liyang,项目名称:grpc-mate,代码行数:18,代码来源:ProductDaoTest.java

示例2: queryByMultiGet

import org.elasticsearch.action.get.GetResponse; //导入依赖的package包/类
/**
 * 获取多个对象(根据ID)
 *
 * @param transportClient
 * @throws IOException
 */
private static void queryByMultiGet(TransportClient transportClient) throws IOException {

	MultiGetResponse multiGetItemResponses = transportClient.prepareMultiGet()
			.add("product_index", "product", "1")
			.add("product_index", "product", "2")
			.add("product_index", "product", "3")
			.add("product_index", "product", "4")
			.add("product_index", "product", "5")
			.get();

	String resultJSON = null;
	for (MultiGetItemResponse multiGetItemResponse : multiGetItemResponses) {
		GetResponse getResponse = multiGetItemResponse.getResponse();
		if (getResponse.isExists()) {
			resultJSON = getResponse.getSourceAsString();
		}
	}
	logger.info("--------------------------------:" + resultJSON);
}
 
开发者ID:judasn,项目名称:Elasticsearch-Tutorial-zh-CN,代码行数:26,代码来源:BaseDemo.java

示例3: getDocument

import org.elasticsearch.action.get.GetResponse; //导入依赖的package包/类
/**
 * This method get the matched document
 */
@Override
public void getDocument() {
    try {
        client = ESclient.getInstant();
        GetResponse response = client.prepareGet("school", "tytenthpe", "1")
                .setOperationThreaded(false)
                .get();
        if (response != null) {
            Map<String, GetField> FieldsMap = response.getFields();
            log.info("Response Data : " + FieldsMap.toString());
        }
    } catch (Exception ex) {
        log.error("Exception occurred while get Document : " + ex, ex);
    }
}
 
开发者ID:sundarcse1216,项目名称:es-crud,代码行数:19,代码来源:ElasticSearchCrudImpl.java

示例4: get

import org.elasticsearch.action.get.GetResponse; //导入依赖的package包/类
@Override
public String get(String workflowInstanceId, String fieldToGet) {
	Object value = null;
	GetRequest request = new GetRequest(indexName, WORKFLOW_DOC_TYPE, workflowInstanceId).storedFields(fieldToGet);
	GetResponse response = client.get(request).actionGet();
	Map<String, GetField> fields = response.getFields();
	if(fields == null) {
		return null;
	}
	GetField field = fields.get(fieldToGet);		
	if(field != null) value = field.getValue();
	if(value != null) {
		return value.toString();
	}
	return null;
}
 
开发者ID:Netflix,项目名称:conductor,代码行数:17,代码来源:ElasticSearchDAO.java

示例5: toMultiGetResponse

import org.elasticsearch.action.get.GetResponse; //导入依赖的package包/类
public MultiGetResponse toMultiGetResponse() {
    List<Map> docs = getAs(entityWrapper, "docs", List.class);
    MultiGetItemResponse[] itemResponses = new MultiGetItemResponse[docs.size()];
    for (int i = 0; i < docs.size(); i++) {
        Map<String, Object> doc = docs.get(i);
        MultiGetResponse.Failure failure = null;
        GetResponse getResponse = null;
        if (doc.containsKey("error")) {
            String index = getAsString(doc, "_index");
            String type = getAsString(doc, "_type");
            String id = getAsString(doc, "_id");
            String error = getAsString(doc, "error");
            failure = new MultiGetResponse.Failure(index, type, id, error);
        } else {
            getResponse = GetResponseAccessor.build(toGetResult(doc, doc));
        }
        MultiGetItemResponse itemResponse = new MultiGetItemResponse(getResponse, failure);
        itemResponses[i] = itemResponse;
    }
    return new MultiGetResponse(itemResponses);
}
 
开发者ID:obourgain,项目名称:elasticsearch-http,代码行数:22,代码来源:ResponseWrapper.java

示例6: test_get

import org.elasticsearch.action.get.GetResponse; //导入依赖的package包/类
private void test_get(final Client client, final String index,
        final String type, final String id, final byte[] hash1,
        final byte[] hash2, final byte[] hash3) {
    final GetResponse response = client
            .prepareGet(index, type, id)
            .setFields("_source", "minhash_value1", "minhash_value2",
                    "minhash_value3").execute().actionGet();
    assertTrue(response.isExists());
    final Map<String, Object> source = response.getSourceAsMap();
    assertEquals("test " + Integer.parseInt(id) % 100, source.get("msg"));

    final GetField field1 = response.getField("minhash_value1");
    final BytesArray value1 = (BytesArray) field1.getValue();
    assertEquals(hash1.length, value1.length());
    Assert.assertArrayEquals(hash1, value1.array());

    final GetField field2 = response.getField("minhash_value2");
    final BytesArray value2 = (BytesArray) field2.getValue();
    assertEquals(hash2.length, value2.length());
    Assert.assertArrayEquals(hash2, value2.array());

    final GetField field3 = response.getField("minhash_value3");
    final BytesArray value3 = (BytesArray) field3.getValue();
    assertEquals(hash3.length, value3.length());
    Assert.assertArrayEquals(hash3, value3.array());
}
 
开发者ID:sherlok,项目名称:sherlastic,代码行数:27,代码来源:SherlokPluginTest.java

示例7: getMultipleDocument

import org.elasticsearch.action.get.GetResponse; //导入依赖的package包/类
/**
 * This method get the multiple Documents
 */
@Override
public void getMultipleDocument() {
    try {
        client = ESclient.getInstant();
        MultiGetResponse multipleItems = client.prepareMultiGet()
                .add("school", "tenth", "1")
                .add("school", "nineth", "1", "2", "3", "4")
                .add("college", "be", "1")
                .get();

        multipleItems.forEach(multipleItem -> {
            GetResponse response = multipleItem.getResponse();
            if (response.isExists()) {
                String json = response.getSourceAsString();
                log.info("Respense Data : " + json);
            }
        });
    } catch (Exception ex) {
        log.error("Exception occurred while get Multiple Document : " + ex, ex);
    }
}
 
开发者ID:sundarcse1216,项目名称:es-crud,代码行数:25,代码来源:ElasticSearchCrudImpl.java

示例8: executeGet

import org.elasticsearch.action.get.GetResponse; //导入依赖的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

示例9: invoke

import org.elasticsearch.action.get.GetResponse; //导入依赖的package包/类
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    if (method.equals(Client.class.getMethod("get", GetRequest.class))) {
        return new PlainActionFuture<GetResponse>() {
            @Override
            public GetResponse get() throws InterruptedException, ExecutionException {
                return delegate.executeGet((GetRequest) args[0]);
            }
        };
    } else if (method.equals(Client.class.getMethod("multiTermVectors", MultiTermVectorsRequest.class))) {
        return new PlainActionFuture<MultiTermVectorsResponse>() {
            @Override
            public MultiTermVectorsResponse get() throws InterruptedException, ExecutionException {
                return delegate.executeMultiTermVectors((MultiTermVectorsRequest) args[0]);
            }
        };
    } else if (method.equals(Object.class.getMethod("toString"))) {
        return "MockClient";
    }
    throw new UnsupportedOperationException("this test can't handle calls to: " + method);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:22,代码来源:AbstractQueryTestCase.java

示例10: assertRealtimeGetWorks

import org.elasticsearch.action.get.GetResponse; //导入依赖的package包/类
void assertRealtimeGetWorks(String indexName) {
    assertAcked(client().admin().indices().prepareUpdateSettings(indexName).setSettings(Settings.builder()
            .put("refresh_interval", -1)
            .build()));
    SearchRequestBuilder searchReq = client().prepareSearch(indexName).setQuery(QueryBuilders.matchAllQuery());
    SearchHit hit = searchReq.get().getHits().getAt(0);
    String docId = hit.getId();
    // foo is new, it is not a field in the generated index
    client().prepareUpdate(indexName, "doc", docId).setDoc(Requests.INDEX_CONTENT_TYPE, "foo", "bar").get();
    GetResponse getRsp = client().prepareGet(indexName, "doc", docId).get();
    Map<String, Object> source = getRsp.getSourceAsMap();
    assertThat(source, Matchers.hasKey("foo"));

    assertAcked(client().admin().indices().prepareUpdateSettings(indexName).setSettings(Settings.builder()
            .put("refresh_interval", IndexSettings.DEFAULT_REFRESH_INTERVAL)
            .build()));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:18,代码来源:OldIndexBackwardsCompatibilityIT.java

示例11: executeGet

import org.elasticsearch.action.get.GetResponse; //导入依赖的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

示例12: getFact

import org.elasticsearch.action.get.GetResponse; //导入依赖的package包/类
/**
 * Retrieve an indexed Fact by its UUID. Returns NULL if Fact cannot be fetched from ElasticSearch.
 *
 * @param id UUID of indexed Fact
 * @return Indexed Fact or NULL if not available
 */
public FactDocument getFact(UUID id) {
  if (id == null) return null;
  GetResponse response;

  try {
    GetRequest request = new GetRequest(INDEX_NAME, TYPE_NAME, id.toString());
    response = clientFactory.getHighLevelClient().get(request);
  } catch (IOException ex) {
    throw logAndExit(ex, String.format("Could not perform request to fetch Fact with id = %s.", id));
  }

  if (response.isExists()) {
    LOGGER.info("Successfully fetched Fact with id = %s.", id);
    return decodeFactDocument(id, response.getSourceAsBytes());
  } else {
    // Fact isn't indexed in ElasticSearch, log warning and return null.
    LOGGER.warning("Could not fetch Fact with id = %s. Fact not indexed?", id);
    return null;
  }
}
 
开发者ID:mnemonic-no,项目名称:act-platform,代码行数:27,代码来源:FactSearchManager.java

示例13: testConvertGetResponseToDocument

import org.elasticsearch.action.get.GetResponse; //导入依赖的package包/类
@Test
public void testConvertGetResponseToDocument() {
    // Test data
    final GetResponse getResponse = createMock(GetResponse.class);
    final Class<AbstractEsDocument> clazz = AbstractEsDocument.class;
    final String source = "source";
    final String id = "id";
    final Person document = new Person();
    // Reset
    resetAll();
    // Expectations
    expect(getResponse.getSourceAsString()).andReturn(source);
    expect(jsonComponent.deserialize(source, clazz)).andReturn(document);
    expect(getResponse.getId()).andReturn(id);
    // Replay
    replayAll();
    // Run test scenario
    final AbstractEsDocument response = searchResponseComponent.convertGetResponseToDocument(getResponse, clazz);
    // Verify
    verifyAll();
    assertNotNull(response);
    assertEquals(document, response);
    assertEquals(id, response.getUuid());
}
 
开发者ID:Biacode,项目名称:escommons,代码行数:25,代码来源:SearchResponseComponentImplTest.java

示例14: getSource

import org.elasticsearch.action.get.GetResponse; //导入依赖的package包/类
/**
 * Returns the source (a map of fields and values) for and object.
 * The source is extracted from the index directly not the data store.
 * @param appid name of the {@link com.erudika.para.core.App}
 * @param key the object id
 * @return a map representation of the object
 */
protected Map<String, Object> getSource(String appid, String key) {
	Map<String, Object> map = new HashMap<String, Object>();
	if (StringUtils.isBlank(key) || StringUtils.isBlank(appid)) {
		return map;
	}

	try {
		GetRequestBuilder grb = client().prepareGet().setIndex(getIndexName(appid)).setId(key);
		GetResponse gres = grb.execute().actionGet();
		if (gres.isExists()) {
			map = gres.getSource();
		}
	} catch (IndexNotFoundException ex) {
		logger.warn("Index not created yet. Call '_setup' first.");
	} catch (Exception e) {
		Throwable cause = e.getCause();
		String msg = cause != null ? cause.getMessage() : e.getMessage();
		logger.warn("Could not get any data from index '{}': {}", appid, msg);
	}
	return map;
}
 
开发者ID:Erudika,项目名称:para-search-elasticsearch,代码行数:29,代码来源:ElasticSearch.java

示例15: handleRequest

import org.elasticsearch.action.get.GetResponse; //导入依赖的package包/类
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
    final GetRequest getRequest = new GetRequest(request.param("index"), request.param("type"), request.param("id"));
    getRequest.operationThreaded(true);
    getRequest.refresh(request.paramAsBoolean("refresh", getRequest.refresh()));
    getRequest.routing(request.param("routing"));  // order is important, set it after routing, so it will set the routing
    getRequest.parent(request.param("parent"));
    getRequest.preference(request.param("preference"));
    getRequest.realtime(request.paramAsBoolean("realtime", null));
    // don't get any fields back...
    getRequest.fields(Strings.EMPTY_ARRAY);
    // TODO we can also just return the document size as Content-Length

    client.get(getRequest, new RestResponseListener<GetResponse>(channel) {
        @Override
        public RestResponse buildResponse(GetResponse response) {
            if (!response.isExists()) {
                return new BytesRestResponse(NOT_FOUND);
            } else {
                return new BytesRestResponse(OK);
            }
        }
    });
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:25,代码来源:RestHeadAction.java


注:本文中的org.elasticsearch.action.get.GetResponse类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。