use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.index.IndexResponse in project YCSB by brianfrankcooper.
the class ElasticsearchClient method insert.
@Override
public Status insert(String table, String key, Map<String, ByteIterator> values) {
try (XContentBuilder doc = jsonBuilder()) {
doc.startObject();
for (final Entry<String, String> entry : StringByteIterator.getStringMap(values).entrySet()) {
doc.field(entry.getKey(), entry.getValue());
}
doc.field(KEY, key);
doc.endObject();
final IndexResponse indexResponse = client.prepareIndex(indexKey, table).setSource(doc).get();
if (indexResponse.getResult() != DocWriteResponse.Result.CREATED) {
return Status.ERROR;
}
if (!isRefreshNeeded) {
synchronized (this) {
isRefreshNeeded = true;
}
}
return Status.OK;
} catch (final Exception e) {
e.printStackTrace();
return Status.ERROR;
}
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.index.IndexResponse in project graylog2-server by Graylog2.
the class MessagesES7IT method indexMessage.
@Override
protected boolean indexMessage(String index, Map<String, Object> source, String id) {
final IndexRequest indexRequest = new IndexRequest(index).source(source).id(id);
final IndexResponse result = this.elasticsearch.elasticsearchClient().execute((c, requestOptions) -> c.index(indexRequest, requestOptions));
return result.status().equals(RestStatus.CREATED);
}
use of org.graylog.shaded.elasticsearch7.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.graylog.shaded.elasticsearch7.org.elasticsearch.action.index.IndexResponse in project jstorm by alibaba.
the class TestIndexBolt method execute.
@Override
public void execute(Tuple tuple) {
String line = tuple.getString(0);
String[] dims = line.split("\t");
JsonObject object = new JsonObject();
object.addProperty("no", dims[1]);
object.addProperty("date", dims[2]);
IndexResponse indexResponse = client.prepareIndex("test", "test").setId(dims[0]).setSource(object.toString()).execute().actionGet();
collector.ack(tuple);
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.index.IndexResponse in project xmall by Exrick.
the class ItemESMessageListener method onMessage.
@Override
public void onMessage(Message message) {
try {
// 从消息中取商品id
TextMessage textMessage = (TextMessage) message;
log.info("得到消息:" + textMessage.getText());
String[] text = textMessage.getText().split(",");
Long itemId = new Long(text[1]);
// 等待事务提交
Thread.sleep(1000);
// 更新索引
Settings settings = Settings.builder().put("cluster.name", ES_CLUSTER_NAME).build();
TransportClient client = new PreBuiltTransportClient(settings).addTransportAddress(new TransportAddress(InetAddress.getByName(ES_CONNECT_IP), 9300));
if ("add".equals(text[0])) {
// 根据商品id查询商品信息
SearchItem searchItem = itemMapper.getItemById(itemId);
String image = searchItem.getProductImageBig();
if (image != null && !"".equals(image)) {
String[] strings = image.split(",");
image = strings[0];
} else {
image = "";
}
searchItem.setProductImageBig(image);
IndexResponse indexResponse = client.prepareIndex(ITEM_INDEX, ITEM_TYPE, String.valueOf(searchItem.getProductId())).setSource(jsonBuilder().startObject().field("productId", searchItem.getProductId()).field("salePrice", searchItem.getSalePrice()).field("productName", searchItem.getProductName()).field("subTitle", searchItem.getSubTitle()).field("productImageBig", searchItem.getProductImageBig()).field("categoryName", searchItem.getCategoryName()).field("cid", searchItem.getCid()).endObject()).get();
} else if ("delete".equals(text[0])) {
DeleteResponse deleteResponse = client.prepareDelete(ITEM_INDEX, ITEM_TYPE, String.valueOf(itemId)).get();
}
log.info("处理消息成功");
client.close();
} catch (Exception e) {
e.printStackTrace();
}
}
Aggregations