Search in sources :

Example 91 with IndexResponse

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.index.IndexResponse in project bw-calendar-engine by Bedework.

the class BwIndexEsImpl method indexEntity.

@Override
public void indexEntity(final Object rec) throws CalFacadeException {
    try {
        /* XXX later with batch
      XmlEmit xml;

      if (batchMaxSize > 0) {
        synchronized (batchLock) {

          if (batchCurSize == 0) {
            batch = new XmlEmit();
            xmlWtr = new StringWriter();
            batch.startEmit(xmlWtr);

            batch.openTag(solrTagAdd);
          }

          index(batch, rec);

          if (batchMaxSize == batchCurSize) {
            batch.closeTag(solrTagAdd);
            indexAndCommit(xmlWtr.toString());
            batchCurSize = 0;
          }
        }

        return;
      }
      */
        // Unbatched
        markUpdated(docTypeFromClass(rec.getClass()));
        final IndexResponse resp = index(rec);
        if (debug) {
            if (resp == null) {
                debug("IndexResponse: resp=null");
            } else {
                debug("IndexResponse: index=" + resp.getIndex() + " id=" + resp.getId() + " type=" + resp.getType() + " version=" + resp.getVersion());
            }
        }
    } catch (final Throwable t) {
        if (debug) {
            error(t);
        }
        throw new CalFacadeException(t);
    } finally {
        lastIndexTime = System.currentTimeMillis();
    }
}
Also used : CreateIndexResponse(org.elasticsearch.action.admin.indices.create.CreateIndexResponse) DeleteIndexResponse(org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse) IndexResponse(org.elasticsearch.action.index.IndexResponse) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 92 with IndexResponse

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.index.IndexResponse in project tutorials by eugenp.

the class ElasticSearchManualTest method givenDocumentId_whenJavaObject_thenDeleteDocument.

@Test
public void givenDocumentId_whenJavaObject_thenDeleteDocument() {
    String jsonObject = "{\"age\":10,\"dateOfBirth\":1471455886564,\"fullName\":\"Johan Doe\"}";
    IndexResponse response = client.prepareIndex("people", "Doe").setSource(jsonObject).get();
    String id = response.getId();
    DeleteResponse deleteResponse = client.prepareDelete("people", "Doe", id).get();
    assertTrue(deleteResponse.isFound());
}
Also used : DeleteResponse(org.elasticsearch.action.delete.DeleteResponse) IndexResponse(org.elasticsearch.action.index.IndexResponse) Test(org.junit.Test)

Example 93 with IndexResponse

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.index.IndexResponse in project tutorials by eugenp.

the class ElasticSearchManualTest method givenJsonString_whenJavaObject_thenIndexDocument.

@Test
public void givenJsonString_whenJavaObject_thenIndexDocument() {
    String jsonObject = "{\"age\":20,\"dateOfBirth\":1471466076564,\"fullName\":\"John Doe\"}";
    IndexResponse response = client.prepareIndex("people", "Doe").setSource(jsonObject).get();
    String index = response.getIndex();
    String type = response.getType();
    assertTrue(response.isCreated());
    assertEquals(index, "people");
    assertEquals(type, "Doe");
}
Also used : IndexResponse(org.elasticsearch.action.index.IndexResponse) Test(org.junit.Test)

Example 94 with IndexResponse

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.index.IndexResponse in project tutorials by eugenp.

the class GeoQueriesTest method givenGeoPointData_whenExecutedGeoDistanceQuery_thenResultNonEmpty.

@Test
public void givenGeoPointData_whenExecutedGeoDistanceQuery_thenResultNonEmpty() {
    String jsonObject = "{\"name\":\"Lighthouse of alexandria\",\"location\":[31.131302,29.976480]}";
    IndexResponse response = client.prepareIndex(WONDERS_OF_WORLD, WONDERS).setSource(jsonObject).get();
    String lighthouseOfAlexandriaId = response.getId();
    client.admin().indices().prepareRefresh(WONDERS_OF_WORLD).get();
    QueryBuilder qb = QueryBuilders.geoDistanceQuery("location").point(29.976, 31.131).distance(10, DistanceUnit.MILES);
    SearchResponse searchResponse = client.prepareSearch(WONDERS_OF_WORLD).setTypes(WONDERS).setQuery(qb).execute().actionGet();
    List<String> ids = Arrays.stream(searchResponse.getHits().getHits()).map(SearchHit::getId).collect(Collectors.toList());
    assertTrue(ids.contains(lighthouseOfAlexandriaId));
}
Also used : IndexResponse(org.elasticsearch.action.index.IndexResponse) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) SearchResponse(org.elasticsearch.action.search.SearchResponse) Test(org.junit.Test)

Example 95 with IndexResponse

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.index.IndexResponse in project tutorials by eugenp.

the class GeoQueriesTest method givenGeoShapeData_whenExecutedGeoShapeQuery_thenResultNonEmpty.

@Test
public void givenGeoShapeData_whenExecutedGeoShapeQuery_thenResultNonEmpty() {
    String jsonObject = "{\"name\":\"Agra\",\"region\":{\"type\":\"envelope\",\"coordinates\":[[75,25],[80.1,30.2]]}}";
    IndexResponse response = client.prepareIndex(WONDERS_OF_WORLD, WONDERS).setSource(jsonObject).get();
    String tajMahalId = response.getId();
    client.admin().indices().prepareRefresh(WONDERS_OF_WORLD).get();
    QueryBuilder qb = QueryBuilders.geoShapeQuery("region", ShapeBuilder.newEnvelope().topLeft(74.00, 24.0).bottomRight(81.1, 31.2)).relation(ShapeRelation.WITHIN);
    SearchResponse searchResponse = client.prepareSearch(WONDERS_OF_WORLD).setTypes(WONDERS).setQuery(qb).execute().actionGet();
    List<String> ids = Arrays.stream(searchResponse.getHits().getHits()).map(SearchHit::getId).collect(Collectors.toList());
    assertTrue(ids.contains(tajMahalId));
}
Also used : IndexResponse(org.elasticsearch.action.index.IndexResponse) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) SearchResponse(org.elasticsearch.action.search.SearchResponse) Test(org.junit.Test)

Aggregations

IndexResponse (org.elasticsearch.action.index.IndexResponse)108 Test (org.junit.Test)26 SearchResponse (org.elasticsearch.action.search.SearchResponse)18 IOException (java.io.IOException)17 CreateIndexResponse (org.elasticsearch.action.admin.indices.create.CreateIndexResponse)17 IndexRequest (org.elasticsearch.action.index.IndexRequest)16 HashMap (java.util.HashMap)15 DeleteResponse (org.elasticsearch.action.delete.DeleteResponse)14 ElasticsearchException (org.elasticsearch.ElasticsearchException)12 CountDownLatch (java.util.concurrent.CountDownLatch)10 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)10 Settings (org.elasticsearch.common.settings.Settings)9 BulkResponse (org.elasticsearch.action.bulk.BulkResponse)7 GetResponse (org.elasticsearch.action.get.GetResponse)7 ArrayList (java.util.ArrayList)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)6 DocWriteRequest (org.elasticsearch.action.DocWriteRequest)6 CreateIndexRequest (org.elasticsearch.action.admin.indices.create.CreateIndexRequest)6 DeleteIndexResponse (org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse)6 UpdateResponse (org.elasticsearch.action.update.UpdateResponse)6