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