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();
}
}
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());
}
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");
}
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));
}
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));
}
Aggregations