Examples of IndexRequestBuilder


Examples of org.elasticsearch.action.index.IndexRequestBuilder

            if(deleted) {
                DeleteRequest deleteRequest = client.prepareDelete(index, type, id).request();
                bulkDeleteRequests.put(id, deleteRequest);
            } else {
                IndexRequestBuilder indexBuilder = client.prepareIndex(index, type, id);
                indexBuilder.setSource(toBeIndexed);
                if(ttl > 0) {
                    indexBuilder.setTTL(ttl);
                }
                if(parentField != null) {
                    Object parent = JSONMapPath(toBeIndexed, parentField);
                    if (parent != null && parent instanceof String ) {
                        indexBuilder.setParent((String)parent);
                    } else {
                        logger.warn("Unabled to determine parent value from parent field {} for doc id {}", parentField, id);
                    }
                }
                if(routingField != null) {
                    Object routing = JSONMapPath(toBeIndexed, routingField);
                    if (routing != null && routing instanceof String) {
                        indexBuilder.setRouting((String)routing);
                    } else {
                        logger.warn("Unable to determine routing value from routing field {} for doc id {}", routingField, id);
                    }
                }
                IndexRequest indexRequest = indexBuilder.request();
                bulkIndexRequests.put(id,  indexRequest);
            }
        }

        List<Object> result = null;
View Full Code Here

Examples of org.elasticsearch.action.index.IndexRequestBuilder

        if(documentRevision == null) {
            // if there isn't one we need to generate a revision number
            documentRevision = generateRevisionNumber();
            document.put("_rev", documentRevision);
        }
        IndexRequestBuilder indexBuilder = client.prepareIndex(index, docType, docId);
        indexBuilder.setSource(document);
        IndexResponse response = indexBuilder.execute().actionGet();
        if(response != null) {
            return documentRevision;
        }
        return null;
    }
View Full Code Here

Examples of org.elasticsearch.action.index.IndexRequestBuilder

        Map<String,Object> doc = new HashMap<String, Object>();
        doc.put("uuid", uuid);
        Map<String, Object> toBeIndexed = new HashMap<String, Object>();
        toBeIndexed.put("doc", doc);

        IndexRequestBuilder builder = client.prepareIndex();
        builder.setIndex(bucket);
        builder.setId(id);
        builder.setType(this.checkpointDocumentType);
        builder.setSource(toBeIndexed);
        builder.setOpType(OpType.CREATE);

        IndexResponse response;
        ListenableActionFuture<IndexResponse> laf = builder.execute();
        if(laf != null) {
            response = laf.actionGet();
            if(!response.isCreated()) {
                logger.error("did not succeed creating uuid");
            }
View Full Code Here

Examples of org.elasticsearch.action.index.IndexRequestBuilder

        Map<String,Object> doc = new HashMap<String, Object>();
        doc.put("uuid", uuid);
        Map<String, Object> toBeIndexed = new HashMap<String, Object>();
        toBeIndexed.put("doc", doc);

        IndexRequestBuilder builder = client.prepareIndex();
        builder.setIndex(bucket);
        builder.setId(id);
        builder.setType(this.checkpointDocumentType);
        builder.setSource(toBeIndexed);
        builder.setOpType(OpType.CREATE);

        IndexResponse response;
        ListenableActionFuture<IndexResponse> laf = builder.execute();
        if(laf != null) {
            response = laf.actionGet();
            if(!response.isCreated()) {
                logger.error("did not succeed creating uuid");
            }
View Full Code Here

Examples of org.elasticsearch.action.index.IndexRequestBuilder

     * get indexRequest to index from a specific request
     *
     * @return
     */
    public static IndexRequestBuilder getIndexRequest(IndexQueryPath indexPath, String id, Index indexable) {
        return new IndexRequestBuilder(IndexClient.client, indexPath.index)
                .setType(indexPath.type)
                .setId(id)
                .setSource(indexable.toIndex());
    }
View Full Code Here

Examples of org.elasticsearch.action.index.IndexRequestBuilder

                    .endObject();
        } catch (IOException e) {
            Logger.error("Elasticsearch : Error when creating percolator from a queryBuilder", e);
        }

        IndexRequestBuilder percolatorRequest =
                IndexClient.client.prepareIndex(indexName,
                        PERCOLATOR_TYPE,
                        queryName)
                        .setSource(source)
                        .setRefresh(immediatelyAvailable);

        return percolatorRequest.execute().actionGet();
    }
View Full Code Here

Examples of org.elasticsearch.action.index.IndexRequestBuilder

    public static IndexResponse createPercolator(String namePercolator, String query) {
        return createPercolator(INDEX_DEFAULT,namePercolator,query,false);
    }

    public static IndexResponse createPercolator(String indexName, String queryName, String query, boolean immediatelyAvailable) {
        IndexRequestBuilder percolatorRequest =
                IndexClient.client.prepareIndex(indexName,
                        PERCOLATOR_TYPE,
                        queryName)
                        .setSource("{\"query\": " + query + "}")
                        .setRefresh(immediatelyAvailable);

        return percolatorRequest.execute().actionGet();
    }
View Full Code Here

Examples of org.elasticsearch.action.index.IndexRequestBuilder

        String indexType = exchange.getIn().getHeader(ElasticsearchConfiguration.PARAM_INDEX_TYPE, String.class);
        if (indexType == null) {
            indexType = getEndpoint().getConfig().getIndexType();
        }

        IndexRequestBuilder prepareIndex = client.prepareIndex(indexName, indexType);

        if (!setIndexRequestSource(exchange.getIn(), prepareIndex)) {
            throw new ExpectedBodyTypeException(exchange, XContentBuilder.class);
        }
        ListenableActionFuture<IndexResponse> future = prepareIndex.execute();
        IndexResponse response = future.actionGet();
        exchange.getIn().setBody(response.getId());
    }
View Full Code Here

Examples of org.elasticsearch.action.index.IndexRequestBuilder

    if (so == null || StringUtils.isBlank(appid)) {
      return;
    }
    Map<String, Object> data = Utils.getAnnotatedFields(so, null, false);
    try {
      IndexRequestBuilder irb = client().prepareIndex(appid, so.getType(), so.getId()).
          setSource(data).setRouting(so.getShardKey());
      if (ttl > 0) {
        irb.setTTL(ttl);
      }
      irb.execute().actionGet();
      logger.debug("Search.index() {}", so.getId());
    } catch (Exception e) {
      logger.warn(null, e);
    }
  }
View Full Code Here

Examples of org.elasticsearch.action.index.IndexRequestBuilder

    if (so == null || StringUtils.isBlank(appid)) {
      return;
    }
    Map<String, Object> data = Utils.getAnnotatedFields(so, null, false);
    try {
      IndexRequestBuilder irb = client().prepareIndex(appid,
          so.getType(), so.getId()).setSource(data);
      if (ttl > 0) {
        irb.setTTL(ttl);
      }
      irb.execute().actionGet();
      logger.debug("Search.index() {}", so.getId());
    } catch (Exception e) {
      logger.warn(null, e);
    }
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.