private void setMetadata(String id, String value) { esClient.prepareIndex(MetadataIndexDefinition.INDEX_TYPE_METADATA) .setId(id) .setSource(MetadataIndexDefinition.FIELD_VALUE, value) .setRefreshPolicy(REFRESH_IMMEDIATE) .get(); } }
@Test public void recreate_index_on_definition_changes() { // v1 startNewCreator(new FakeIndexDefinition()); IndexType fakeIndexType = new IndexType("fakes", "fake"); String id = "1"; es.client().prepareIndex(fakeIndexType).setId(id).setSource(new FakeDoc().getFields()).setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE).get(); assertThat(es.client().prepareGet(fakeIndexType, id).get().isExists()).isTrue(); // v2 startNewCreator(new FakeIndexDefinitionV2()); ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> mappings = mappings(); MappingMetaData mapping = mappings.get("fakes").get("fake"); assertThat(countMappingFields(mapping)).isEqualTo(3); assertThat(field(mapping, "updatedAt").get("type")).isEqualTo("date"); assertThat(field(mapping, "newField").get("type")).isEqualTo("integer"); assertThat(es.client().prepareGet(fakeIndexType, id).get().isExists()).isFalse(); }
@Test public void do_not_recreate_index_on_unchanged_definition() { // v1 startNewCreator(new FakeIndexDefinition()); IndexType fakeIndexType = new IndexType("fakes", "fake"); String id = "1"; es.client().prepareIndex(fakeIndexType).setId(id).setSource(new FakeDoc().getFields()).setRefreshPolicy(IMMEDIATE).get(); assertThat(es.client().prepareGet(fakeIndexType, id).get().isExists()).isTrue(); // v1 startNewCreator(new FakeIndexDefinition()); assertThat(es.client().prepareGet(fakeIndexType, id).get().isExists()).isTrue(); }
public IndexResponse insert(final String index, final String type, final String id, final String source) { return insert(index, type, id, builder -> builder.setSource(source, xContentType(source)).setRefreshPolicy(RefreshPolicy.IMMEDIATE)); }
@Override public void index(KObject object) { MetaObject metaObject = fieldFactory.build(object); elasticSearchMappingStore.updateMetaModel(object, metaObject); this.deleteIfExists(object); this.createIndexRequest((ElasticMetaObject) metaObject) .setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE) .execute().actionGet(); }
@Override public void index(KObject object) { MetaObject metaObject = fieldFactory.build(object); elasticSearchMappingStore.updateMetaModel(object, metaObject); this.deleteIfExists(object); this.createIndexRequest((ElasticMetaObject) metaObject) .setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE) .execute().actionGet(); }
private void setMetadata(String id, String value) { esClient.prepareIndex(MetadataIndexDefinition.INDEX_TYPE_METADATA) .setId(id) .setSource(MetadataIndexDefinition.FIELD_VALUE, value) .setRefreshPolicy(REFRESH_IMMEDIATE) .get(); } }
/** * Index one entity model by its type. Return error if an entity model already exists for that entity type. * * @param entityType The entity type. * @param requestBody The request body. * @param client The client that will communicate with Elasticsearch. * @return The response from Elasticsearch. * @throws ForbiddenException */ public static IndexResponse indexEntityModel(String entityType, String requestBody, NodeClient client) throws ForbiddenException { ensureIndex(client); IndexRequestBuilder request = client.prepareIndex(INDEX_NAME, "doc", entityType); request.setSource(requestBody, XContentType.JSON).setCreate(true).setRefreshPolicy("wait_for"); return request.get(); }
/** * Update one entity model by its type. Does not support partial updates. * * @param entityType The entity type. * @param requestBody The request body. * @param client The client that will communicate with Elasticsearch. * @return The response from Elasticsearch. * @throws ForbiddenException */ public static IndexResponse updateEntityModel(String entityType, String requestBody, NodeClient client) throws ForbiddenException { ensureIndex(client); IndexRequestBuilder request = client.prepareIndex(INDEX_NAME, "doc", entityType); request.setSource(requestBody, XContentType.JSON).setCreate(false).setRefreshPolicy("wait_for"); return request.get(); }
.endObject() .setRefreshPolicy(IMMEDIATE) .execute() .get();