private void setMetadata(String id, String value) { esClient.prepareIndex(MetadataIndexDefinition.INDEX_TYPE_METADATA) .setId(id) .setSource(MetadataIndexDefinition.FIELD_VALUE, value) .setRefreshPolicy(REFRESH_IMMEDIATE) .get(); } }
private IndexRequest newIndexRequest(IssueDoc issue) { String projectUuid = issue.projectUuid(); return esClient.prepareIndex(INDEX_TYPE_ISSUE) .setId(issue.key()) .setRouting(projectUuid) .setParent(projectUuid) .setSource(issue.getFields()) .request(); }
requestBuilder.setId( "" + row[idFieldIndex] ); // "" just in case field isn't string
@Override public void execute(Tuple tuple) { try { String index = mapper.getIndex(tuple); String type = mapper.getType(tuple); String id = mapper.getId(tuple); String source = mapper.getSource(tuple); OpType opType = mapper.getOpType(); client.prepareIndex(index, type).setId(id).setSource(source) .setOpType(opType).execute(); collector.ack(tuple); } catch (Exception e) { collector.fail(tuple); } }
@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 void create(PhotonDoc doc) { try { this.bulkRequest.add(this.esClient.prepareIndex("photon", "place").setSource(Utils.convert(doc, this.languages)).setId(String.valueOf(doc.getPlaceId()))); } catch (IOException e) { log.error(String.format("creation of new doc [%s] failed", doc), e); } }
@Override public IndexRequestBuilder prepareIndex(String index, String type, @Nullable String id) { return prepareIndex().setIndex(index).setType(type).setId(id); }
@Override public void add(PhotonDoc doc) { try { this.bulkRequest.add(this.esClient.prepareIndex(indexName, indexType). setSource(Utils.convert(doc, languages)).setId(doc.getUid())); } catch (IOException e) { log.error("could not bulk add document " + doc.getUid(), e); return; } this.documentCount += 1; if (this.documentCount > 0 && this.documentCount % 10000 == 0) { this.saveDocuments(); } }
private IndexRequestBuilder createIndex(Object object) { Map<String, String> indexInformation = (Map<String, String>) object; IndexRequestBuilder prepareIndex = client.prepareIndex(); if (indexInformation.containsKey(INDEX_NAME_ELEMENT)) { prepareIndex.setIndex(indexInformation.get(INDEX_NAME_ELEMENT)); } if (indexInformation.containsKey(INDEX_TYPE_ELEMENT)) { prepareIndex.setType(indexInformation.get(INDEX_TYPE_ELEMENT)); } if (indexInformation.containsKey(INDEX_ID_ELEMENT)) { prepareIndex.setId(indexInformation.get(INDEX_ID_ELEMENT)); } return prepareIndex; }
private IndexRequestBuilder createIndex(Object object) { @SuppressWarnings("unchecked") final Map<String, String> indexInformation = (Map<String, String>) object; final IndexRequestBuilder prepareIndex = client.prepareIndex(); if (indexInformation.containsKey(INDEX_NAME_ELEMENT)) { prepareIndex.setIndex(indexInformation.get(INDEX_NAME_ELEMENT)); } if (indexInformation.containsKey(INDEX_TYPE_ELEMENT)) { prepareIndex.setType(indexInformation.get(INDEX_TYPE_ELEMENT)); } if (indexInformation.containsKey(INDEX_ID_ELEMENT)) { prepareIndex.setId(indexInformation.get(INDEX_ID_ELEMENT)); } return prepareIndex; }
private IndexRequestBuilder createIndex(Object object) { Map<String, String> indexInformation = (Map<String, String>) object; IndexRequestBuilder prepareIndex = client.prepareIndex(); if (indexInformation.containsKey(INDEX_NAME_ELEMENT)) { prepareIndex.setIndex(indexInformation.get(INDEX_NAME_ELEMENT)); } if (indexInformation.containsKey(INDEX_TYPE_ELEMENT)) { prepareIndex.setType(indexInformation.get(INDEX_TYPE_ELEMENT)); } if (indexInformation.containsKey(INDEX_ID_ELEMENT)) { prepareIndex.setId(indexInformation.get(INDEX_ID_ELEMENT)); } return prepareIndex; }
private boolean insert(String id, Map source) { Preconditions.checkNotNull(source, "source must not be null."); logger.info("insert data : {}", JSON.toJSONString(source)); IndexRequestBuilder builder = client.prepareIndex(index, type).setSource(source); if (StringUtils.isNotBlank(id)) { builder.setId(id); } IndexResponse response = builder.get(); logger.info("insert response : {}", response.toString()); return response.isCreated(); }
/** * 通过ID查询 IndexResponse * * @param _id * @return */ public IndexResponse insert(String _id, String source) { EsLogUtils.info("执行新增 {}/{}?{}", this.index, this.type, source); return this.indexRequest().setId(_id).setSource(source, XContentType.JSON).execute().actionGet(); }
@Override public IndexRequestBuilder prepareIndex(final String index, final String type, @Nullable final String id) { return new IndexRequestBuilder(this, index).setType(type).setId(id); }
@Override public IndexRequestBuilder prepareIndex(final String index, final String type, @Nullable final String id) { return new IndexRequestBuilder(this, index).setType(type).setId(id); }
private void setMetadata(String id, String value) { esClient.prepareIndex(MetadataIndexDefinition.INDEX_TYPE_METADATA) .setId(id) .setSource(MetadataIndexDefinition.FIELD_VALUE, value) .setRefreshPolicy(REFRESH_IMMEDIATE) .get(); } }
@Override public IndexRequestBuilder prepareIndex(String index, String type, @Nullable String id) { return prepareIndex().setIndex(index).setType(type).setId(id); }
@Override public IndexRequestBuilder prepareIndex(String index, String type, @Nullable String id) { return prepareIndex().setIndex(index).setType(type).setId(id); }
private IndexRequest newIndexRequest(IssueDoc issue) { String projectUuid = issue.projectUuid(); return esClient.prepareIndex(INDEX_TYPE_ISSUE) .setId(issue.key()) .setRouting(projectUuid) .setParent(projectUuid) .setSource(issue.getFields()) .request(); }