当前位置: 首页>>代码示例>>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;未经允许,请勿转载。