Package org.elasticsearch.action.get

Examples of org.elasticsearch.action.get.GetResponse


     * @return Zero on success, a non-zero error code on error or "not found".
     */
    @Override
    public int read(String table, String key, Set<String> fields, HashMap<String, ByteIterator> result) {
        try {
            final GetResponse response = client.prepareGet(indexKey, table, key)
                    .execute()
                    .actionGet();

            if (response.isExists()) {
                if (fields != null) {
                    for (String field : fields) {
                        result.put(field, new StringByteIterator((String) response.getSource().get(field)));
                    }
                } else {
                    for (String field : response.getSource().keySet()) {
                        result.put(field, new StringByteIterator((String) response.getSource().get(field)));
                    }
                }
                return 0;
            }
        } catch (Exception e) {
View Full Code Here


     * description for a discussion of error codes.
     */
    @Override
    public int update(String table, String key, HashMap<String, ByteIterator> values) {
        try {
            final GetResponse response = client.prepareGet(indexKey, table, key)
                    .execute()
                    .actionGet();

            if (response.isExists()) {
                for (Entry<String, String> entry : StringByteIterator.getStringMap(values).entrySet()) {
                    response.getSource().put(entry.getKey(), entry.getValue());
                }

                client.prepareIndex(indexKey, table, key)
                        .setSource(response.getSource())
                        .execute()
                        .actionGet();

                return 0;
            }
View Full Code Here

                }

                String lastSeq = null;
                try {
                    client.admin().indices().prepareRefresh(riverIndexName).execute().actionGet();
                    GetResponse lastSeqGetResponse = client.prepareGet(riverIndexName, riverName().name(), "_seq").execute().actionGet();
                    if (lastSeqGetResponse.isExists()) {
                        Map<String, Object> couchdbState = (Map<String, Object>) lastSeqGetResponse.getSourceAsMap().get("couchdb");
                        if (couchdbState != null) {
                            lastSeq = couchdbState.get("last_seq").toString(); // we know its always a string
                        }
                    }
                } catch (Exception e) {
View Full Code Here

  }

  @Test
  public void shouldMapGetRequestToObject() {
    //Given
    GetResponse response = mock(GetResponse.class);
    when(response.getSourceAsString()).thenReturn(createJsonCar("Ford", "Grat"));

    //When
    Car result = resultMapper.mapResult(response, Car.class);

    //Then
View Full Code Here

        // Check that the river is started
        assertThat(awaitBusy(new Predicate<Object>() {
            public boolean apply(Object obj) {
                try {
                    refresh();
                    GetResponse response = get("_river", getDbName(), "_status");
                    return response.isExists();
                } catch (IndexMissingException e) {
                    return false;
                }
            }
        }, 5, TimeUnit.SECONDS), equalTo(true));

        logger.info("  -> Creating test database [{}]", getDbName());
        CouchDBClient.dropAndCreateTestDatabase(getDbName());

        logger.info("  -> Inserting [{}] docs in couchdb", nbDocs);
        for (int i = 0; i < nbDocs; i++) {
            CouchDBClient.putDocument(getDbName(), "" + i, "foo", "bar", "content", "" + i);
        }

        // Check that docs are still processed by the river
        assertThat(awaitBusy(new Predicate<Object>() {
            public boolean apply(Object obj) {
                try {
                    refresh();
                    SearchResponse response = client().prepareSearch(getDbName()).get();
                    logger.info("  -> got {} docs in {} index", response.getHits().totalHits(), getDbName());
                    return response.getHits().totalHits() == nbDocs;
                } catch (IndexMissingException e) {
                    return false;
                }
            }
        }, 1, TimeUnit.MINUTES), equalTo(true));
View Full Code Here

  }

  @Override
  public <T> T queryForObject(GetQuery query, Class<T> clazz, GetResultMapper mapper) {
    ElasticsearchPersistentEntity<T> persistentEntity = getPersistentEntityFor(clazz);
    GetResponse response = client
        .prepareGet(persistentEntity.getIndexName(), persistentEntity.getIndexType(), query.getId()).execute()
        .actionGet();

    T entity = mapper.mapResult(response, clazz);
    return entity;
View Full Code Here

    ListenableActionFuture<GetResponse> addActionFuture = client.prepareGet()
        .setIndex(stage.getIndex())
        .setType(stage.getType())
        .setId(stage.getDocumentId(addDocument))
        .execute();
    GetResponse addResponse = addActionFuture.actionGet();
    Assert.assertTrue("The document should have been added to the index", addResponse.exists());
    Assert.assertEquals("Document should be added to correct index", stage.getIndex(), addResponse.getIndex());
    Assert.assertEquals("Document should have correct type", stage.getType(), addResponse.getType());

    stage.output(deleteDocument);
   
    ListenableActionFuture<GetResponse> deleteActionFuture = client.prepareGet()
        .setIndex(stage.getIndex())
        .setType(stage.getType())
        .setId(stage.getDocumentId(addDocument))
        .execute();
    GetResponse deleteResponse = deleteActionFuture.actionGet();
    Assert.assertFalse("The document should not be in the index", deleteResponse.exists());
  }
View Full Code Here

      throw new IllegalStateException("Jira River must be stopped to reconfigure it!");

    logger.info("reconfiguring JIRA River");
    String riverIndexName = getRiverIndexName();
    refreshSearchIndex(riverIndexName);
    GetResponse resp = client.prepareGet(riverIndexName, riverName().name(), "_meta").execute().actionGet();
    if (resp.isExists()) {
      if (logger.isDebugEnabled()) {
        logger.debug("Configuration document: {}", resp.getSourceAsString());
      }
      Map<String, Object> newset = resp.getSource();
      configure(newset);
    } else {
      throw new IllegalStateException("Configuration document not found to reconfigure jira river "
          + riverName().name());
    }
View Full Code Here

    if (logger.isDebugEnabled())
      logger.debug("Going to read datetime value from {} property for project {}. Document name is {}.", propertyName,
          projectKey, documentName);

    refreshSearchIndex(getRiverIndexName());
    GetResponse lastSeqGetResponse = client.prepareGet(getRiverIndexName(), riverName.name(), documentName).execute()
        .actionGet();
    if (lastSeqGetResponse.isExists()) {
      Object timestamp = lastSeqGetResponse.getSourceAsMap().get(STORE_FIELD_VALUE);
      if (timestamp != null) {
        lastDate = DateTimeUtils.parseISODateTime(timestamp.toString());
      }
    } else {
      if (logger.isDebugEnabled())
View Full Code Here

      throw new IllegalStateException("Jira River must be stopped to reconfigure it!");

    logger.info("reconfiguring JIRA River");
    String riverIndexName = getRiverIndexName();
    refreshSearchIndex(riverIndexName);
    GetResponse resp = client.prepareGet(riverIndexName, riverName().name(), "_meta").execute().actionGet();
    if (resp.isExists()) {
      if (logger.isDebugEnabled()) {
        logger.debug("Configuration document: {}", resp.getSourceAsString());
      }
      Map<String, Object> newset = resp.getSource();
      configure(newset);
    } else {
      throw new IllegalStateException("Configuration document not found to reconfigure jira river "
          + riverName().name());
    }
View Full Code Here

TOP

Related Classes of org.elasticsearch.action.get.GetResponse

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.