use of org.elasticsearch.action.index.IndexResponse in project elasticsearch-opennlp-plugin by spinscale.
the class OpenNlpPluginIntegrationTest method testThatFacetingIsWorking.
@Test
public void testThatFacetingIsWorking() throws Exception {
putMapping("/test-mapping-analyzers.json");
String sampleText = copyToStringFromClasspath("/sample-text.txt");
IndexResponse indexResponse = indexElement(sampleText);
SearchResponse searchResponse = new SearchRequestBuilder(node.client()).setIndices(index).setTypes(type).setQuery(QueryBuilders.matchAllQuery()).addFacet(new TermsFacetBuilder("names").field("someFieldAnalyzed.name").order(TermsFacet.ComparatorType.TERM)).execute().actionGet();
assertThat(searchResponse.getHits().totalHits(), is(1L));
assertThat(searchResponse.getHits().getAt(0).id(), is(indexResponse.getId()));
TermsFacet termsFacet = searchResponse.getFacets().facet(TermsFacet.class, "names");
assertThat(termsFacet.getTotalCount(), is(2L));
assertThat(termsFacet.getEntries().get(0).getTerm().string(), is("Jack Nicholson"));
assertThat(termsFacet.getEntries().get(1).getTerm().string(), is("Kobe Bryant"));
}
use of org.elasticsearch.action.index.IndexResponse in project elasticsearch-graphite-plugin by spinscale.
the class GraphitePluginIntegrationTest method masterFailOverShouldWork.
@Test
public void masterFailOverShouldWork() throws Exception {
node = createNode(clusterName, GRAPHITE_SERVER_PORT, "1s");
String clusterName = UUID.randomUUID().toString().replaceAll("-", "");
IndexResponse indexResponse = indexElement(node, index, type, "value");
assertThat(indexResponse.getId(), is(notNullValue()));
Node origNode = node;
node = createNode(clusterName, GRAPHITE_SERVER_PORT, "1s");
graphiteMockServer.content.clear();
origNode.stop();
indexResponse = indexElement(node, index, type, "value");
assertThat(indexResponse.getId(), is(notNullValue()));
// wait for master fail over and writing to graph reporter
Thread.sleep(2000);
assertGraphiteMetricIsContained("elasticsearch." + clusterName + ".indexes." + index + ".id.0.indexing._all.indexCount 1");
}
use of org.elasticsearch.action.index.IndexResponse in project elasticsearch-graphite-plugin by spinscale.
the class GraphitePluginIntegrationTest method testThatIndexingResultsInMonitoring.
@Test
public void testThatIndexingResultsInMonitoring() throws Exception {
node = createNode(clusterName, GRAPHITE_SERVER_PORT, "1s");
IndexResponse indexResponse = indexElement(node, index, type, "value");
assertThat(indexResponse.getId(), is(notNullValue()));
Thread.sleep(2000);
ensureValidKeyNames();
assertGraphiteMetricIsContained("^elasticsearch." + clusterName + ".indexes." + index + ".id.0.indexing._all.indexCount 1");
assertGraphiteMetricIsContained("^elasticsearch." + clusterName + ".indexes." + index + ".id.0.indexing." + type + ".indexCount 1");
assertGraphiteMetricIsContained("^elasticsearch." + clusterName + ".indexes." + index + ".id.0.search._all.queryCount ");
assertGraphiteMetricIsContained("^elasticsearch." + clusterName + ".node.jvm.threads.peakCount ");
assertGraphiteMetricIsContained("^elasticsearch." + clusterName + ".node.search._all.queryCount ");
}
use of org.elasticsearch.action.index.IndexResponse in project fess by codelibs.
the class FessEsClient method store.
public boolean store(final String index, final String type, final Object obj) {
final FessConfig fessConfig = ComponentUtil.getFessConfig();
@SuppressWarnings("unchecked") final Map<String, Object> source = obj instanceof Map ? (Map<String, Object>) obj : BeanUtil.copyBeanToNewMap(obj);
final String id = (String) source.remove(fessConfig.getIndexFieldId());
final Long version = (Long) source.remove(fessConfig.getIndexFieldVersion());
IndexResponse response;
try {
if (id == null) {
// create
response = client.prepareIndex(index, type).setSource(new DocMap(source)).setRefreshPolicy(RefreshPolicy.IMMEDIATE).setOpType(OpType.CREATE).execute().actionGet(fessConfig.getIndexIndexTimeout());
} else {
// create or update
final IndexRequestBuilder builder = client.prepareIndex(index, type, id).setSource(new DocMap(source)).setRefreshPolicy(RefreshPolicy.IMMEDIATE).setOpType(OpType.INDEX);
if (version != null && version.longValue() > 0) {
builder.setVersion(version);
}
response = builder.execute().actionGet(fessConfig.getIndexIndexTimeout());
}
final Result result = response.getResult();
return result == Result.CREATED || result == Result.UPDATED;
} catch (final ElasticsearchException e) {
throw new FessEsClientException("Failed to store: " + obj, e);
}
}
use of org.elasticsearch.action.index.IndexResponse in project fess by codelibs.
the class EsAbstractBehavior method delegateUpdate.
@Override
protected int delegateUpdate(final Entity entity, final UpdateOption<? extends ConditionBean> option) {
final EsAbstractEntity esEntity = (EsAbstractEntity) entity;
final IndexRequestBuilder builder = createUpdateRequest(esEntity);
final IndexResponse response = builder.execute().actionGet(indexTimeout);
long version = response.getVersion();
if (version != -1) {
esEntity.asDocMeta().version(version);
}
return 1;
}
Aggregations