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


Java GetResponse.getSourceAsString方法代码示例

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


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

示例1: 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

示例2: load

import org.elasticsearch.action.get.GetResponse; //导入方法依赖的package包/类
public String load(String id) {
	String settings = SpaceContext.getSettings(id);

	if (settings == null) {
		String backendId = SpaceContext.backendId();
		ElasticClient elastic = Start.get().getElasticClient();

		if (elastic.existsIndex(backendId, TYPE)) {
			GetResponse response = elastic.get(backendId, TYPE, id);

			if (response.isExists()) {
				settings = response.getSourceAsString();
				SpaceContext.setSettings(id, settings);
			}
		}

		if (settings == null)
			throw Exceptions.notFound(backendId, TYPE, id);
	}

	return settings;
}
 
开发者ID:spacedog-io,项目名称:spacedog-server,代码行数:23,代码来源:SettingsResource.java

示例3: getIndex

import org.elasticsearch.action.get.GetResponse; //导入方法依赖的package包/类
/**
 * 获取索引信息
 * @param index
 * @param type
 * @param id
 */
private static void getIndex(String index, String type, String id){
	Client client = createTransportClient();
	GetResponse response = client.prepareGet(index, type, id)
	        .execute()
	        .actionGet();
	boolean exists = response.isExists();
	System.out.println(exists);// 判断索引是否存在
	String sourceString = response.getSourceAsString();
	System.out.println(sourceString);// 获取索引,并且打印出索引内容
	System.out.println("****************index ***********************");
	// Index name
	String _index = response.getIndex();
	// Type name
	String _type = response.getType();
	// Document ID (generated or not)
	String _id = response.getId();
	// Version (if it's the first time you index this document, you will get: 1)
	long _version = response.getVersion();
	System.out.println(_index+","+_type+","+_id+","+_version);
}
 
开发者ID:ameizi,项目名称:elasticsearch-jest-example,代码行数:27,代码来源:TransportClient.java

示例4: findById

import org.elasticsearch.action.get.GetResponse; //导入方法依赖的package包/类
@Override
public T findById(K key) throws Exception {
    String index = mapping.indexForKey(key);
    String type = mapping.typeForKey(key);
    String id = mapping.idForKey(key);
    try {
        GetResponse response = client.prepareGet(index, type, id).execute().actionGet();
        String source = response.getSourceAsString();
        if (source == null) {
            return null;
        } else {
            T result = mapping.fromDocument(id, source);
            return result;
        }
    } catch (Exception e) {
        log.error("error retrieving dao", e);
        throw e;
    }
}
 
开发者ID:scaleset,项目名称:scaleset-search,代码行数:20,代码来源:ElasticSearchDao.java

示例5: queryUser

import org.elasticsearch.action.get.GetResponse; //导入方法依赖的package包/类
@Override
public JSONObject queryUser(String index, String type, String id) {
	GetResponse getResponse = esClient.prepareGet(index, type, id).get(); 
	String sourceAsString = getResponse.getSourceAsString();
	JSONObject res = JSONObject.parseObject(sourceAsString);
	return res;
}
 
开发者ID:SnailFastGo,项目名称:springboot_op,代码行数:8,代码来源:ESServiceImpl.java

示例6: select

import org.elasticsearch.action.get.GetResponse; //导入方法依赖的package包/类
public String select(String index,String type,String id){
	try {
		if(xclient==null){
			init();
		}
		GetRequest request = new GetRequest(index, type, id);
		GetResponse result = xclient.get(request);
		return result.getSourceAsString();
	} catch (Exception e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	return null;
}
 
开发者ID:dev-share,项目名称:css-elasticsearch,代码行数:15,代码来源:ElasticsearchHighRestFactory.java

示例7: select

import org.elasticsearch.action.get.GetResponse; //导入方法依赖的package包/类
public String select(String index,String type,String id){
	try {
		if(client==null){
			init();
		}
		GetResponse result = client.prepareGet(index, type, id).execute().actionGet();
		return result.getSourceAsString();
	} catch (Exception e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	return null;
}
 
开发者ID:dev-share,项目名称:css-elasticsearch,代码行数:14,代码来源:ElasticsearchTransportFactory.java

示例8: test1

import org.elasticsearch.action.get.GetResponse; //导入方法依赖的package包/类
@Test
public void test1(){
    try{
        Settings settings = Settings.builder()
                .put("cluster.name", "xmall").build();
        TransportClient client = new PreBuiltTransportClient(settings)
                .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("123.207.121.135"), 9300));

        IndexResponse response = client.prepareIndex("item", "itemList", "830972")
                .setSource(jsonBuilder()
                        .startObject()
                        .field("productId", "830972")
                        .field("salePrice", "254")
                        .field("productName", "254")
                        .field("sub_title", "524")
                        .field("productImageBig", "252")
                        .field("category_name", "2542")
                        .endObject()
                ).get();

        GetResponse getResponse = client.prepareGet("item", "itemList", "830972").get();

        String json = getResponse.getSourceAsString();

        System.out.println(json);

        client.close();
    }catch (Exception e){
        e.printStackTrace();
    }
}
 
开发者ID:Exrick,项目名称:xmall,代码行数:32,代码来源:ElasticsearchTest.java

示例9: name

import org.elasticsearch.action.get.GetResponse; //导入方法依赖的package包/类
@Test
public void name() throws Exception {
    MultiGetResponse multiGetItemResponses = client.prepareMultiGet()
            .add("twitter", "tweet", "1")
            .add("twitter", "tweet", "2", "3", "4")
            .add("another", "type", "foo")
            .get();
    for (MultiGetItemResponse itemResponse : multiGetItemResponses) {
        GetResponse response = itemResponse.getResponse();
        if (response.isExists()) {
            String json = response.getSourceAsString();
        }
    }
}
 
开发者ID:felayman,项目名称:elasticsearch-full,代码行数:15,代码来源:MultiGetDemo.java

示例10: read

import org.elasticsearch.action.get.GetResponse; //导入方法依赖的package包/类
public Person read(String userName) throws IOException {
    Person person = null;
    GetResponse response = client.prepareGet(ES_INDEX, ES_DOCTYPE, userName).get();
    if (response != null) {
        String personJson = response.getSourceAsString();
        try {
            if (personJson != null)
                person = objectMapper.readValue(personJson, Person.class);
        } catch (IOException e) {
            LOGGER.error("Error while deserializing Person document from elasticsearch");
            throw e;
        }
    }
    return person;
}
 
开发者ID:echauchot,项目名称:bigDataRocks,代码行数:16,代码来源:PersonElasticsearchDao.java

示例11: findOne

import org.elasticsearch.action.get.GetResponse; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public Optional<T> findOne(final String id) {
  final GetResponse response = client
    .prepareGet(index, type, id)
    .setFetchSource(true)
    .execute()
    .actionGet();
  final String json = response.getSourceAsString();
  return ofNullable(json)
    .map(deserializer)
    .map(e -> (T) e.withId(id));
}
 
开发者ID:jloisel,项目名称:elastic-crud,代码行数:14,代码来源:ElasticSearchRepository.java

示例12: findAll

import org.elasticsearch.action.get.GetResponse; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public List<T> findAll(final List<String> ids) {
  if (ids.isEmpty()) {
    return ImmutableList.of();
  }

  final Builder<T> builder = ImmutableList.builder();

  final MultiGetResponse response = client
    .prepareMultiGet()
    .add(index, type, ids)
    .execute()
    .actionGet();

  for(final MultiGetItemResponse item : response.getResponses()) {
    final GetResponse get = item.getResponse();
    if(get.isSourceEmpty()) {
      continue;
    }

    final String json = get.getSourceAsString();
    final T entity = deserializer.apply(json);
    builder.add((T) entity.withId(get.getId()));
  }

  return builder.build();
}
 
开发者ID:jloisel,项目名称:elastic-crud,代码行数:29,代码来源:ElasticSearchRepository.java

示例13: fromGetResponse

import org.elasticsearch.action.get.GetResponse; //导入方法依赖的package包/类
public static PersistentServiceDef fromGetResponse(GetResponse getResponse) {
    long persistentVersion = getResponse.getVersion();
    JsonObject document = new JsonObject(getResponse.getSourceAsString());

    return new PersistentServiceDef(getResponse.getId(), persistentVersion)
            .merge(document);
}
 
开发者ID:pitchpoint-solutions,项目名称:sfs,代码行数:8,代码来源:PersistentServiceDef.java

示例14: fromGetResponse

import org.elasticsearch.action.get.GetResponse; //导入方法依赖的package包/类
public static PersistentContainer fromGetResponse(PersistentAccount persistentAccount, GetResponse getResponse) {
    JsonObject document = new JsonObject(getResponse.getSourceAsString());

    return
            new PersistentContainer(persistentAccount, getResponse.getId(), getResponse.getVersion())
                    .merge(document);

}
 
开发者ID:pitchpoint-solutions,项目名称:sfs,代码行数:9,代码来源:PersistentContainer.java

示例15: testMultiGet

import org.elasticsearch.action.get.GetResponse; //导入方法依赖的package包/类
@Test
public void testMultiGet() {
    MultiGetResponse multiGetItemResponses = client.prepareMultiGet().add("twitter", "tweet", "1").add("twitter", "tweet", "2", "3", "4")
            .add("another", "type", "foo").get();

    for (MultiGetItemResponse itemResponse : multiGetItemResponses) {
        GetResponse response = itemResponse.getResponse();
        if (response.isExists()) {
            String json = response.getSourceAsString();
            System.out.println(json);
        }
    }
}
 
开发者ID:dzh,项目名称:jframe,代码行数:14,代码来源:TestTransportClient.java


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