日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

elasticsearch api中的get操作

發布時間:2024/1/23 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 elasticsearch api中的get操作 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

官網:https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/java-docs-index.html


The get API allows to get a typed JSON document from the index based onits id. The following example gets a JSON document from an index calledtwitter, under a type called tweet, with id valued 1:

GetResponse response = client.prepareGet("twitter", "tweet", "1").get();

For more information on the get operation, check out the RESTget docs.

Operation Threadingedit

The get API allows to set the threading model the operation will beperformed when the actual execution of the API is performed on the samenode (the API is executed on a shard that is allocated on the sameserver).

The options are to execute the operation on a different thread, or toexecute it on the calling thread (note that the API is still async). Bydefault,operationThreaded is set to true which means the operationis executed on a different thread. Here is an example that sets it tofalse:

GetResponse response = client.prepareGet("twitter", "tweet", "1").setOperationThreaded(false).get();


練習源碼:

package es.documentApi;

import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;

import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.transport.client.PreBuiltTransportClient;

public class ElasticSearchGet {

?? ?public static void main(String[] args) {
?? ??? ?try {
?? ??? ??? ?// 設置集群名稱
?? ??? ??? ?Settings settings = Settings.builder().put("cluster.name", "my-elasticsearch")
?? ??? ??? ??? ??? ?.put("client.transport.sniff", true).build();
?? ??? ??? ?// 創建client
?? ??? ??? ?TransportClient client = new PreBuiltTransportClient(settings)
?? ??? ??? ??? ??? ?.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("192.168.224.140"), 9300))
?? ??? ??? ??? ??? ?.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("192.168.224.141"), 9300))
?? ??? ??? ??? ??? ?.addTransportAddress(
?? ??? ??? ??? ??? ??? ??? ?new InetSocketTransportAddress(InetAddress.getByName("192.168.224.142"), 9300));

?? ??? ??? ?GetResponse response = client.prepareGet("twitter", "tweet", "1").get();
?? ??? ??? ?GetResponse response1 = client.prepareGet("twitter", "tweet", "1")
?? ??? ??? ???????? .setOperationThreaded(false)
?? ??? ??? ???????? .get();
?? ??? ??? ?String res = response.getSourceAsString();
?? ??? ??? ?client.close();
?? ??? ?} catch (UnknownHostException e) {
?? ??? ??? ?e.printStackTrace();
?? ??? ?} catch (IOException e) {
?? ??? ??? ?e.printStackTrace();
?? ??? ?}

?? ?}

}


最后得到查詢結果:

no modules loaded
loaded plugin [org.elasticsearch.index.reindex.ReindexPlugin]
loaded plugin [org.elasticsearch.percolator.PercolatorPlugin]
loaded plugin [org.elasticsearch.script.mustache.MustachePlugin]
loaded plugin [org.elasticsearch.transport.Netty3Plugin]
loaded plugin [org.elasticsearch.transport.Netty4Plugin]
{
??? "title":"my sense",
??? "author":"sxx",
??? "content":"sense is a good tool"
}

總結

以上是生活随笔為你收集整理的elasticsearch api中的get操作的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。