Package org.elasticsearch.action.index

Examples of org.elasticsearch.action.index.IndexRequest


    private void indexProducts(List<Map<String, Object>> products, String index, String routing) throws Exception {
        long currentCount = getCurrentDocumentCount(index);
        BulkRequest bulkRequest = new BulkRequest();
        for (Map<String, Object> product : products) {
            IndexRequest indexRequest = new IndexRequest(index, "product", (String)product.get("ProductId"));
            indexRequest.source(product);
            if (Strings.hasLength(routing)) {
                indexRequest.routing(routing);
            }
            bulkRequest.add(indexRequest);
        }
        bulkRequest.refresh(true);
        BulkResponse response = client().bulk(bulkRequest).actionGet();
View Full Code Here


                   
                    while (results != null && results.hasMore()) {
                       
                        SearchResult sr = (SearchResult) results.next();
                       
                        IndexRequest indexRequest = new IndexRequest(indexName);
                       
                        XContentBuilder builder = jsonBuilder();
                        builder.startObject();
                       
                        String dn = sr.getName();
                        logger.debug("Reading ldap object dn [{}]", dn);
                       
                        Attributes ldapAttributes = sr.getAttributes();
                        NamingEnumeration<String> ldapAttributesIds = ldapAttributes.getIDs();
                        while (ldapAttributesIds.hasMoreElements()) {
                            String id = ldapAttributesIds.next();
                            logger.debug("\treading attribute id [{}]", id);
                           
                            List<String> fieldValues = new ArrayList<String>();
                            Attribute attribute = ldapAttributes.get(id);
                            NamingEnumeration<?> values = attribute.getAll();
                            while (values.hasMoreElements()) {
                                Object value = values.next();
                                logger.debug("\t\tvalue: [{}]", value.toString());
                                fieldValues.add(value.toString());
                            }
                            String fieldName = resolveFieldName(id);
                            if(fieldValues.size() > 1){
                                builder.array(fieldName, fieldValues.toArray());
                            } else {
                                if (!"_id".equals(fieldName)) {
                                    builder.field(fieldName, fieldValues.get(0));
                                } else {
                                    indexRequest.id(fieldValues.get(0));
                                }
                            }
                        }

                        builder.endObject();
                       
                        indexRequest.type(typeName).source(builder);
                        bulkRequest.add(indexRequest);
                        count++;
                       
                        if((count % bulkSize) == 0){
                            BulkResponse bulkResponse = bulkRequest.execute().actionGet(bulkTimeout);
View Full Code Here

            }
            if (closed) {
                logger.warn("river was closing while trying to index document [{}/{}/{}]. Operation skipped.", index, type, id);
                return null;
            }
            bulkProcessor.add(new IndexRequest(index, type, id).source(doc).routing(extractRouting(ctx)).parent(extractParent(ctx)));
        } else {
            logger.warn("ignoring unknown change {}", s);
        }
        return seq;
    }
View Full Code Here

                        }
                        if (closed) {
                            logger.warn("river was closing while trying to update sequence [{}/{}/{}]. Operation skipped.", riverIndexName, riverName.name(), "_seq");
                            return;
                        }
                        bulkProcessor.add(new IndexRequest(riverIndexName, riverName.name(), "_seq")
                                .source(jsonBuilder().startObject().startObject("couchdb").field("last_seq", lastSeqAsString).endObject().endObject()));
                    } catch (IOException e) {
                        logger.warn("failed to add last_seq entry to bulk indexing");
                    }
                }
View Full Code Here

    IndexQuery indexQuery = getIndexQuery(sampleEntity);

    elasticsearchTemplate.index(indexQuery);
    elasticsearchTemplate.refresh(SampleEntity.class, true);

    IndexRequest indexRequest = new IndexRequest();
    indexRequest.source("message", messageAfterUpdate);
    UpdateQuery updateQuery = new UpdateQueryBuilder().withId(documentId)
        .withClass(SampleEntity.class).withIndexRequest(indexRequest).build();
    // when
    elasticsearchTemplate.update(updateQuery);
    //then
View Full Code Here

  }

  @Test(expected = DocumentMissingException.class)
  public void shouldThrowExceptionIfDocumentDoesNotExistWhileDoingPartialUpdate() {
    // when
    IndexRequest indexRequest = new IndexRequest();
    UpdateQuery updateQuery = new UpdateQueryBuilder().withId(randomNumeric(5))
        .withClass(SampleEntity.class).withIndexRequest(indexRequest).build();
    elasticsearchTemplate.update(updateQuery);
  }
View Full Code Here

  @Test
  public void shouldDoUpsertIfDocumentDoesNotExist() {
    //given
    String documentId = randomNumeric(5);
    String message = "test message";
    IndexRequest indexRequest = new IndexRequest();
    indexRequest.source("message", message);
    UpdateQuery updateQuery = new UpdateQueryBuilder().withId(documentId)
        .withDoUpsert(true).withClass(SampleEntity.class)
        .withIndexRequest(indexRequest).build();
    //when
    elasticsearchTemplate.update(updateQuery);
View Full Code Here

    private final List<IndexRequest> _bulkBuffer = newArrayList();

    private void addToBulk(final int id, final String value1, final String value2,
            final int iValue1, final long lValue) throws IOException {
        final String stringID = String.valueOf(id);
        _bulkBuffer.add(new IndexRequest(__index, __type, stringID)
                .routing(stringID).source(
                        XContentFactory.jsonBuilder()
                                .startObject()
                                .field(__txtField1, value1)
                                .field(__txtField2, value2)
View Full Code Here

                final int idx = i + j;
                if(idx >= ids.length) {
                    bulk.setRefresh(true).execute().actionGet();
                    return;
                }
                bulk.add(new IndexRequest(__index, __type1, ids[idx])
                        .routing(ids[idx])
                        .source(XContentFactory.jsonBuilder()
                                .startObject()
                                .field(__txtField, "Document created by " + users[idx])
                                .field(__userField, users[idx])
View Full Code Here

    StringBuilder message = new StringBuilder();
    message.append("ES bulk request for ");
    for (ActionRequest item : request.requests()) {
      message.append(String.format("[Action '%s' ", item.getClass().getSimpleName()));
      if (item instanceof IndexRequest) {
        IndexRequest request = (IndexRequest) item;
        message.append(String.format("for key '%s'", request.id()));
        message.append(String.format(" on index '%s'", request.index()));
        message.append(String.format(" on type '%s'", request.type()));
      } else if (item instanceof UpdateRequest) {
        UpdateRequest request = (UpdateRequest) item;
        message.append(String.format("for key '%s'", request.id()));
        message.append(String.format(" on index '%s'", request.index()));
        message.append(String.format(" on type '%s'", request.type()));
      } else if (item instanceof DeleteRequest) {
        DeleteRequest request = (DeleteRequest) item;
        message.append(String.format("for key '%s'", request.id()));
        message.append(String.format(" on index '%s'", request.index()));
        message.append(String.format(" on type '%s'", request.type()));
      }
      message.append("],");
    }
    return message.toString();
  }
View Full Code Here

TOP

Related Classes of org.elasticsearch.action.index.IndexRequest

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.