Package org.elasticsearch.action.update

Examples of org.elasticsearch.action.update.UpdateRequestBuilder


    String type = isNotBlank(query.getType()) ? query.getType() : getPersistentEntityFor(query.getClazz()).getIndexType();
    Assert.notNull(indexName, "No index defined for Query");
    Assert.notNull(type, "No type define for Query");
    Assert.notNull(query.getId(), "No Id define for Query");
    Assert.notNull(query.getUpdateRequest(), "No IndexRequest define for Query");
    UpdateRequestBuilder updateRequestBuilder = client.prepareUpdate(indexName, type, query.getId());
    if (query.DoUpsert()) {
      updateRequestBuilder.setDocAsUpsert(true)
          .setDoc(query.getUpdateRequest().doc())
          .setScript(query.getUpdateRequest().script(), query.getUpdateRequest().scriptType())
          .setScriptParams(query.getUpdateRequest().scriptParams())
          .setScriptLang(query.getUpdateRequest().scriptLang());
    } else {
      updateRequestBuilder.setDoc(query.getUpdateRequest().doc());
    }
    return updateRequestBuilder.execute().actionGet();
  }
View Full Code Here


                            brb.add(new IndexRequest(indexName, storename, docid).source(getContent(mutation.getAdditions())));
                            bulkrequests++;
                        } else { //Update: TODO make part of batch mutation if/when possible
                            boolean needUpsert = !mutation.hasDeletions();
                            XContentBuilder builder = getContent(mutation.getAdditions());
                            UpdateRequestBuilder update = client.prepareUpdate(indexName, storename, docid).setDoc(builder);
                            if (needUpsert) update.setUpsert(builder);
                            log.trace("Updating document {} with upsert {}", docid, needUpsert);
                            update.execute().actionGet();
                        }
                    }

                }
            }
View Full Code Here

    @Test
    public void testUpdate() {
        createIndexWithAlias();
        ensureYellow("test");

        UpdateRequestBuilder updateRequestBuilder = client().prepareUpdate(indexOrAlias(), "type1", "1")
                .setUpsert("field1", "value1").setDoc("field2", "value2");

        UpdateResponse updateResponse = updateRequestBuilder.get();
        assertThat(updateResponse.getIndex(), equalTo("test"));
        assertThat(updateResponse.getType(), equalTo("type1"));
        assertThat(updateResponse.getId(), equalTo("1"));
        assertThat(updateResponse.isCreated(), equalTo(true));

        GetResponse getResponse = client().prepareGet("test", "type1", "1").get();
        assertThat(getResponse.isExists(), equalTo(true));
        assertThat(getResponse.getSourceAsMap().containsKey("field1"), equalTo(true));
        assertThat(getResponse.getSourceAsMap().containsKey("field2"), equalTo(false));

        updateResponse = updateRequestBuilder.get();
        assertThat(updateResponse.getIndex(), equalTo("test"));
        assertThat(updateResponse.getType(), equalTo("type1"));
        assertThat(updateResponse.getId(), equalTo("1"));
        assertThat(updateResponse.isCreated(), equalTo(false));
View Full Code Here

        execute(UpdateAction.INSTANCE, request, listener);
    }

    @Override
    public UpdateRequestBuilder prepareUpdate() {
        return new UpdateRequestBuilder(this, null, null, null);
    }
View Full Code Here

        return new UpdateRequestBuilder(this, null, null, null);
    }

    @Override
    public UpdateRequestBuilder prepareUpdate(String index, String type, String id) {
        return new UpdateRequestBuilder(this, index, type, id);
    }
View Full Code Here

            }
        }

        builder = client().prepareBulk();
        for (int i = 0; i < numDocs; i++) {
            UpdateRequestBuilder updateBuilder = client().prepareUpdate()
                    .setIndex("test").setType("type1").setId(Integer.toString(i)).setFields("counter");
            if (i % 2 == 0) {
                updateBuilder.setScript("ctx._source.counter += 1", ScriptService.ScriptType.INLINE);
            } else {
                updateBuilder.setDoc(jsonBuilder().startObject().field("counter", 2).endObject());
            }
            if (i % 3 == 0) {
                updateBuilder.setRetryOnConflict(3);
            }

            builder.add(updateBuilder);
        }
View Full Code Here

TOP

Related Classes of org.elasticsearch.action.update.UpdateRequestBuilder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.