本文整理汇总了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);
}
示例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;
}
示例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);
}
示例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;
}
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}
}
示例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();
}
}
}
示例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;
}
示例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));
}
示例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();
}
示例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);
}
示例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);
}
示例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);
}
}
}