當前位置: 首頁>>代碼示例>>Java>>正文


Java UpdateRequest.index方法代碼示例

本文整理匯總了Java中org.elasticsearch.action.update.UpdateRequest.index方法的典型用法代碼示例。如果您正苦於以下問題:Java UpdateRequest.index方法的具體用法?Java UpdateRequest.index怎麽用?Java UpdateRequest.index使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.elasticsearch.action.update.UpdateRequest的用法示例。


在下文中一共展示了UpdateRequest.index方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: should_marshall_update_request_with_upsert

import org.elasticsearch.action.update.UpdateRequest; //導入方法依賴的package包/類
@Test
public void should_marshall_update_request_with_upsert() throws Exception {
    UpdateRequest request = new UpdateRequest();
    request.index("the_index");
    request.type("the_type");
    request.id("the_id");
    request.upsert("bar", "baz");
    Observable<byte[]> observable = BulkActionMarshaller.lazyConvertToBytes(Collections.<ActionRequest>singletonList(request));
    assertHasSize(observable, 4);

    byte[] bytes = takeNth(observable, 0);
    assertThat(new String(bytes)).isEqualTo("{\"update\":{\"_index\":\"the_index\",\"_type\":\"the_type\",\"_id\":\"the_id\",\"_retry_on_conflict\":0}}");

    bytes = takeNth(observable, 1);
    assertThat(new String(bytes)).isEqualTo("\n");

    bytes = takeNth(observable, 2);
    assertThat(new String(bytes)).isEqualTo("{\"upsert\":{\"bar\":\"baz\"}}");

    bytes = takeNth(observable, 3);
    assertThat(new String(bytes)).isEqualTo("\n");
}
 
開發者ID:obourgain,項目名稱:elasticsearch-http,代碼行數:23,代碼來源:BulkActionMarshallerTest.java

示例2: should_marshall_update_request

import org.elasticsearch.action.update.UpdateRequest; //導入方法依賴的package包/類
@Test
public void should_marshall_update_request() throws Exception {
    UpdateRequest request = new UpdateRequest();
    request.index("the_index");
    request.type("the_type");
    request.id("the_id");
    request.doc("foo", "bar");
    Observable<byte[]> observable = BulkActionMarshaller.lazyConvertToBytes(Collections.<ActionRequest>singletonList(request));
    assertHasSize(observable, 4);

    byte[] bytes = takeNth(observable, 0);
    assertThat(new String(bytes)).isEqualTo("{\"update\":{\"_index\":\"the_index\",\"_type\":\"the_type\",\"_id\":\"the_id\",\"_retry_on_conflict\":0}}");
    bytes = takeNth(observable, 1);
    assertThat(new String(bytes)).isEqualTo("\n");
    bytes = takeNth(observable, 2);
    assertThat(new String(bytes)).isEqualTo("{\"doc\":{\"foo\":\"bar\"}}");
    bytes = takeNth(observable, 3);
    assertThat(new String(bytes)).isEqualTo("\n");
}
 
開發者ID:obourgain,項目名稱:elasticsearch-http,代碼行數:20,代碼來源:BulkActionMarshallerTest.java

示例3: should_marshall_update_request_with_doc_as_upsert

import org.elasticsearch.action.update.UpdateRequest; //導入方法依賴的package包/類
@Test
public void should_marshall_update_request_with_doc_as_upsert() throws Exception {
    UpdateRequest request = new UpdateRequest();
    request.index("the_index");
    request.type("the_type");
    request.id("the_id");
    request.doc("bar", "baz");
    request.docAsUpsert(true);
    Observable<byte[]> observable = BulkActionMarshaller.lazyConvertToBytes(Collections.<ActionRequest>singletonList(request));
    assertHasSize(observable, 4);

    byte[] bytes = takeNth(observable, 0);
    assertThat(new String(bytes)).isEqualTo("{\"update\":{\"_index\":\"the_index\",\"_type\":\"the_type\",\"_id\":\"the_id\",\"_retry_on_conflict\":0}}");

    bytes = takeNth(observable, 1);
    assertThat(new String(bytes)).isEqualTo("\n");

    bytes = takeNth(observable, 2);
    assertThat(new String(bytes)).isEqualTo("{\"doc_as_upsert\":true,\"doc\":{\"bar\":\"baz\"}}");

    bytes = takeNth(observable, 3);
    assertThat(new String(bytes)).isEqualTo("\n");
}
 
開發者ID:obourgain,項目名稱:elasticsearch-http,代碼行數:24,代碼來源:BulkActionMarshallerTest.java

示例4: should_marshall_update_request_with_script

import org.elasticsearch.action.update.UpdateRequest; //導入方法依賴的package包/類
@Test
public void should_marshall_update_request_with_script() throws Exception {
    UpdateRequest request = new UpdateRequest();
    request.index("the_index");
    request.type("the_type");
    request.id("the_id");
    request.script("the_script");
    Observable<byte[]> observable = BulkActionMarshaller.lazyConvertToBytes(Collections.<ActionRequest>singletonList(request));
    assertHasSize(observable, 4);

    byte[] bytes = takeNth(observable, 0);
    assertThat(new String(bytes)).isEqualTo("{\"update\":{\"_index\":\"the_index\",\"_type\":\"the_type\",\"_id\":\"the_id\",\"_retry_on_conflict\":0}}");

    bytes = takeNth(observable, 1);
    assertThat(new String(bytes)).isEqualTo("\n");

    bytes = takeNth(observable, 2);
    assertThat(new String(bytes)).isEqualTo("{\"script\":\"the_script\"}");

    bytes = takeNth(observable, 3);
    assertThat(new String(bytes)).isEqualTo("\n");
}
 
開發者ID:obourgain,項目名稱:elasticsearch-http,代碼行數:23,代碼來源:BulkActionMarshallerTest.java

示例5: should_marshall_update_request_with_script_and_upsert

import org.elasticsearch.action.update.UpdateRequest; //導入方法依賴的package包/類
@Test
public void should_marshall_update_request_with_script_and_upsert() throws Exception {
    UpdateRequest request = new UpdateRequest();
    request.index("the_index");
    request.type("the_type");
    request.id("the_id");
    request.script("the_script");
    request.upsert("bar", "baz");
    Observable<byte[]> observable = BulkActionMarshaller.lazyConvertToBytes(Collections.<ActionRequest>singletonList(request));
    assertHasSize(observable, 4);

    byte[] bytes = takeNth(observable, 0);
    assertThat(new String(bytes)).isEqualTo("{\"update\":{\"_index\":\"the_index\",\"_type\":\"the_type\",\"_id\":\"the_id\",\"_retry_on_conflict\":0}}");

    bytes = takeNth(observable, 1);
    assertThat(new String(bytes)).isEqualTo("\n");

    bytes = takeNth(observable, 2);
    assertThat(new String(bytes)).isEqualTo("{\"upsert\":{\"bar\":\"baz\"},\"script\":\"the_script\"}");

    bytes = takeNth(observable, 3);
    assertThat(new String(bytes)).isEqualTo("\n");
}
 
開發者ID:obourgain,項目名稱:elasticsearch-http,代碼行數:24,代碼來源:BulkActionMarshallerTest.java

示例6: UpdateRequest

import org.elasticsearch.action.update.UpdateRequest; //導入方法依賴的package包/類
private static void UpdateRequest(Client client) throws IOException, InterruptedException, ExecutionException {

        //當更新的內容不存在的時候會添加  
        UpdateRequest updateRequest = new UpdateRequest();
        updateRequest.index("twitter");
        updateRequest.type("tweet");
        updateRequest.id("3");
        XContentBuilder jsonBuilder =XContentFactory.jsonBuilder();
        updateRequest.doc(jsonBuilder
                .startObject()
                .field("message","我是林誌穎啊")
                .field("user","lin")
                .endObject());
        UpdateResponse response= client.update(updateRequest).get();  
           
    /*   
     *  //當更新的內容不存在時候,不會添加 
        UpdateResponse response = client.prepareUpdate("twitter","tweet","1") 
                        .setDoc(jsonBuilder() 
                                 .startObject() 
                                   .field("users4","xue") 
                                 .endObject()) 
                                 .get();*/

        System.out.println(response.getVersion());


    }
 
開發者ID:hs-web,項目名稱:hsweb-learning,代碼行數:29,代碼來源:ElasticSearch.java

示例7: createUpdateRequest

import org.elasticsearch.action.update.UpdateRequest; //導入方法依賴的package包/類
public static UpdateRequestBuilder createUpdateRequest(final Client client, final StreamInput streamInput, final String index)
        throws IOException {
    final UpdateRequestBuilder builder = client.prepareUpdate();
    final UpdateRequest request = builder.request();
    request.readFrom(streamInput);
    if (index != null) {
        request.index(index);
    }
    return builder;
}
 
開發者ID:codelibs,項目名稱:elasticsearch-indexing-proxy,代碼行數:11,代碼來源:RequestUtils.java

示例8: update

import org.elasticsearch.action.update.UpdateRequest; //導入方法依賴的package包/類
/**
 * 更新網頁
 *
 * @param webpage 網頁
 * @return
 */
public boolean update(Webpage webpage) throws ExecutionException, InterruptedException {
    UpdateRequest updateRequest = new UpdateRequest();
    updateRequest.index(INDEX_NAME);
    updateRequest.type(TYPE_NAME);
    updateRequest.id(webpage.getId());
    updateRequest.doc(gson.toJson(webpage));
    UpdateResponse response = client.update(updateRequest).get();
    return response.getResult() == UpdateResponse.Result.UPDATED;
}
 
開發者ID:bruceq,項目名稱:Gather-Platform,代碼行數:16,代碼來源:CommonWebpageDAO.java

示例9: testForClient

import org.elasticsearch.action.update.UpdateRequest; //導入方法依賴的package包/類
@Test
public void testForClient() throws Exception {
    UpdateRequest updateRequest = new UpdateRequest();
    updateRequest.index("index");
    updateRequest.type("type");
    updateRequest.id("1");
    updateRequest.doc(XContentFactory.jsonBuilder()
            .startObject()
            .field("gender", "male")
            .endObject());
    client.update(updateRequest).get();
}
 
開發者ID:felayman,項目名稱:elasticsearch-full,代碼行數:13,代碼來源:UpdateDemo.java

示例10: update

import org.elasticsearch.action.update.UpdateRequest; //導入方法依賴的package包/類
public static void update(Client client ) throws IOException, InterruptedException, ExecutionException {
	UpdateRequest req = new UpdateRequest();
	req.index("search_test");
	req.type("article");
	req.id("2");
	req.doc(jsonBuilder().startObject().field("title", "updated title").field("body", "updated body").endObject());
	client.update(req).get();
	client.close();
}
 
開發者ID:walle-liao,項目名稱:jaf-examples,代碼行數:10,代碼來源:IndexUpdate.java

示例11: updateHeartbeatTime

import org.elasticsearch.action.update.UpdateRequest; //導入方法依賴的package包/類
@Override public void updateHeartbeatTime(int instanceId, long heartbeatTime) {
    ElasticSearchClient client = getClient();
    UpdateRequest updateRequest = new UpdateRequest();
    updateRequest.index(InstanceTable.TABLE);
    updateRequest.type(InstanceTable.TABLE_TYPE);
    updateRequest.id(String.valueOf(instanceId));
    updateRequest.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);

    Map<String, Object> source = new HashMap<>();
    source.put(InstanceTable.COLUMN_HEARTBEAT_TIME, heartbeatTime);

    updateRequest.doc(source);
    client.update(updateRequest);
}
 
開發者ID:apache,項目名稱:incubator-skywalking,代碼行數:15,代碼來源:InstanceRegisterEsDAO.java

示例12: testUpdate

import org.elasticsearch.action.update.UpdateRequest; //導入方法依賴的package包/類
public void testUpdate() throws Exception {
    UpdateRequest updateRequest = new UpdateRequest();
    updateRequest.index("index");
    updateRequest.type("type");
    updateRequest.id("1");
    updateRequest.doc(XContentFactory.jsonBuilder().startObject().field("gender", "male").endObject());
    UpdateResponse response = client.update(updateRequest).get();
    System.out.println(response.toString());

    client.prepareUpdate("ttl", "doc", "1").setScript(new Script("ctx._source.gender = \"male\"", ScriptService.ScriptType.INLINE, null, null))
            .get();

    client.prepareUpdate("ttl", "doc", "1").setDoc(XContentFactory.jsonBuilder().startObject().field("gender", "male").endObject()).get();
}
 
開發者ID:dzh,項目名稱:jframe,代碼行數:15,代碼來源:TestTransportClient.java


注:本文中的org.elasticsearch.action.update.UpdateRequest.index方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。