本文整理汇总了Java中org.elasticsearch.action.DocWriteResponse.Result类的典型用法代码示例。如果您正苦于以下问题:Java Result类的具体用法?Java Result怎么用?Java Result使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Result类属于org.elasticsearch.action.DocWriteResponse包,在下文中一共展示了Result类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: insert
import org.elasticsearch.action.DocWriteResponse.Result; //导入依赖的package包/类
public String insert(String index,String type,Object json){
try {
if(client==null){
init();
}
IndexResponse response = client.prepareIndex(index, type).setSource(JSON.parseObject(JSON.toJSONString(json)),XContentType.JSON).execute().actionGet();
if(response.getResult().equals(Result.CREATED)){
System.out.println(JSON.toJSONString(response));
}
return response.toString();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
示例2: testGetLocation
import org.elasticsearch.action.DocWriteResponse.Result; //导入依赖的package包/类
public void testGetLocation() {
final DocWriteResponse response =
new DocWriteResponse(
new ShardId("index", "uuid", 0),
"type",
"id",
SequenceNumbersService.UNASSIGNED_SEQ_NO,
0,
Result.CREATED) {};
assertEquals("/index/type/id", response.getLocation(null));
assertEquals("/index/type/id?routing=test_routing", response.getLocation("test_routing"));
}
示例3: testGetLocationNonAscii
import org.elasticsearch.action.DocWriteResponse.Result; //导入依赖的package包/类
public void testGetLocationNonAscii() {
final DocWriteResponse response =
new DocWriteResponse(
new ShardId("index", "uuid", 0),
"type",
"❤",
SequenceNumbersService.UNASSIGNED_SEQ_NO,
0,
Result.CREATED) {};
assertEquals("/index/type/%E2%9D%A4", response.getLocation(null));
assertEquals("/index/type/%E2%9D%A4?routing=%C3%A4", response.getLocation("ä"));
}
示例4: testGetLocationWithSpaces
import org.elasticsearch.action.DocWriteResponse.Result; //导入依赖的package包/类
public void testGetLocationWithSpaces() {
final DocWriteResponse response =
new DocWriteResponse(
new ShardId("index", "uuid", 0),
"type",
"a b",
SequenceNumbersService.UNASSIGNED_SEQ_NO,
0,
Result.CREATED) {};
assertEquals("/index/type/a+b", response.getLocation(null));
assertEquals("/index/type/a+b?routing=c+d", response.getLocation("c d"));
}
示例5: testToXContentDoesntIncludeForcedRefreshUnlessForced
import org.elasticsearch.action.DocWriteResponse.Result; //导入依赖的package包/类
/**
* Tests that {@link DocWriteResponse#toXContent(XContentBuilder, ToXContent.Params)} doesn't include {@code forced_refresh} unless it
* is true. We can't assert this in the yaml tests because "not found" is also "false" there....
*/
public void testToXContentDoesntIncludeForcedRefreshUnlessForced() throws IOException {
DocWriteResponse response =
new DocWriteResponse(
new ShardId("index", "uuid", 0),
"type",
"id",
SequenceNumbersService.UNASSIGNED_SEQ_NO,
0,
Result.CREATED) {
// DocWriteResponse is abstract so we have to sneak a subclass in here to test it.
};
response.setShardInfo(new ShardInfo(1, 1));
response.setForcedRefresh(false);
try (XContentBuilder builder = JsonXContent.contentBuilder()) {
response.toXContent(builder, ToXContent.EMPTY_PARAMS);
try (XContentParser parser = createParser(JsonXContent.jsonXContent, builder.bytes())) {
assertThat(parser.map(), not(hasKey("forced_refresh")));
}
}
response.setForcedRefresh(true);
try (XContentBuilder builder = JsonXContent.contentBuilder()) {
response.toXContent(builder, ToXContent.EMPTY_PARAMS);
try (XContentParser parser = createParser(JsonXContent.jsonXContent, builder.bytes())) {
assertThat(parser.map(), hasEntry("forced_refresh", true));
}
}
}
示例6: launchRequestSender
import org.elasticsearch.action.DocWriteResponse.Result; //导入依赖的package包/类
private void launchRequestSender(final String index, final long filePosition, final long version,
final ActionListener<Map<String, Object>> listener) {
if (logger.isDebugEnabled()) {
logger.debug("Launching RequestSender(" + index + ")");
}
final Map<String, Object> source = new HashMap<>();
source.put(IndexingProxyPlugin.NODE_NAME, nodeName());
source.put(IndexingProxyPlugin.FILE_POSITION, filePosition);
source.put(IndexingProxyPlugin.TIMESTAMP, new Date());
source.put(DOC_TYPE, "index");
final IndexRequestBuilder builder =
client.prepareIndex(IndexingProxyPlugin.INDEX_NAME, IndexingProxyPlugin.TYPE_NAME, index).setSource(source).setRefreshPolicy(RefreshPolicy.WAIT_UNTIL);
if (version > 0) {
builder.setVersion(version);
} else {
builder.setCreate(true);
}
builder.execute(wrap(res -> {
if (res.getResult() == Result.CREATED || res.getResult() == Result.UPDATED) {
final RequestSender sender = new RequestSender(settings, client, threadPool, namedWriteableRegistry, nodeName(), dataPath,
index, dataFileFormat, docSenderMap, logger);
final RequestSender oldSender = docSenderMap.put(index, sender);
if (oldSender != null) {
oldSender.terminate();
}
threadPool.schedule(TimeValue.ZERO, Names.GENERIC, sender);
listener.onResponse(source);
} else {
listener.onFailure(new ElasticsearchException("Failed to update .idxproxy index: " + res));
}
}, listener::onFailure));
}
示例7: reorder
import org.elasticsearch.action.DocWriteResponse.Result; //导入依赖的package包/类
@Test
public void reorder() throws Exception {
assertThat(1, is(runner.getNodeSize()));
final Client client = runner.client();
final String index = "sample";
final String alias = "test";
final String type = "data";
CreateIndexResponse createIndexResponse = runner.createIndex(index,
Settings.builder().put(DynamicRanker.SETTING_INDEX_DYNARANK_REORDER_SIZE.getKey(), 100)
.put(DynamicRanker.SETTING_INDEX_DYNARANK_LANG.getKey(), "groovy")
.put(DynamicRanker.SETTING_INDEX_DYNARANK_SCRIPT.getKey(),
"searchHits.sort {s1, s2 -> s2.getSource().get('counter') - s1.getSource().get('counter')} as org.elasticsearch.search.SearchHit[]")
.put(DynamicRanker.SETTING_INDEX_DYNARANK_PARAMS.getKey() + "foo", "bar").build());
assertTrue(createIndexResponse.isAcknowledged());
IndicesAliasesResponse aliasesResponse = runner.updateAlias(alias, new String[] { index }, null);
assertTrue(aliasesResponse.isAcknowledged());
for (int i = 1; i <= 1000; i++) {
final IndexResponse indexResponse1 = runner.insert(index, type, String.valueOf(i),
"{\"id\":\"" + i + "\",\"msg\":\"test " + i + "\",\"counter\":" + i + "}");
assertEquals(Result.CREATED, indexResponse1.getResult());
}
assertResultOrder(client, index, type);
assertResultOrder(client, alias, type);
String index2 = index + "2";
runner.createIndex(index2, (Settings) null);
runner.updateAlias(alias, new String[] { index2 }, null);
int tempId = 99999;
runner.insert(index2, type, String.valueOf(tempId),
"{\"id\":\"" + tempId + "\",\"msg\":\"test " + tempId + "\",\"counter\":" + tempId + "}");
runner.delete(index2, type, String.valueOf(tempId));
runner.refresh();
assertResultOrder(client, alias, type);
}
示例8: insertTestData
import org.elasticsearch.action.DocWriteResponse.Result; //导入依赖的package包/类
private void insertTestData(final String index, final String type, final int id, final String msg, final String category) {
assertEquals(Result.CREATED,
runner.insert(index, type, String.valueOf(id),
"{\"id\":\"" + id + "\",\"msg\":\"" + msg + "\",\"category\":\"" + category + "\",\"order\":" + id + "}")
.getResult());
}
示例9: skipReorder
import org.elasticsearch.action.DocWriteResponse.Result; //导入依赖的package包/类
@Test
public void skipReorder() throws Exception {
assertThat(1, is(runner.getNodeSize()));
final Client client = runner.client();
final String index = "sample";
final String type = "data";
runner.createIndex(index,
Settings.builder().put(DynamicRanker.SETTING_INDEX_DYNARANK_REORDER_SIZE.getKey(), 100)
.put(DynamicRanker.SETTING_INDEX_DYNARANK_SCRIPT.getKey(),
"searchHits.sort {s1, s2 -> s2.getSource().get('counter') - s1.getSource().get('counter')} as org.elasticsearch.search.SearchHit[]")
.put(DynamicRanker.SETTING_INDEX_DYNARANK_PARAMS.getKey() + "foo", "bar").build());
for (int i = 1; i <= 1000; i++) {
final IndexResponse indexResponse1 = runner.insert(index, type, String.valueOf(i),
"{\"id\":\"" + i + "\",\"msg\":\"test " + i + "\",\"counter\":" + i + "}");
assertEquals(Result.CREATED, indexResponse1.getResult());
}
{
final SearchResponse searchResponse = client.prepareSearch(index).setQuery(QueryBuilders.matchAllQuery())
.addSort("counter", SortOrder.ASC).setScroll("1m").execute().actionGet();
final SearchHits hits = searchResponse.getHits();
assertEquals(1000, hits.getTotalHits());
assertEquals(10, hits.getHits().length);
assertEquals("1", hits.getHits()[0].getId());
assertEquals("10", hits.getHits()[9].getId());
}
}
示例10: skipReorder_scrollSearch
import org.elasticsearch.action.DocWriteResponse.Result; //导入依赖的package包/类
@Test
public void skipReorder_scrollSearch() throws Exception {
assertThat(1, is(runner.getNodeSize()));
final Client client = runner.client();
final String index = "sample";
final String type = "data";
runner.createIndex(index,
Settings.builder().put(DynamicRanker.SETTING_INDEX_DYNARANK_REORDER_SIZE.getKey(), 100)
.put(DynamicRanker.SETTING_INDEX_DYNARANK_SCRIPT.getKey(),
"searchHits.sort {s1, s2 -> s2.getSource().get('counter') - s1.getSource().get('counter')} as org.elasticsearch.search.SearchHit[]")
.put(DynamicRanker.SETTING_INDEX_DYNARANK_PARAMS.getKey() + "foo", "bar").build());
for (int i = 1; i <= 1000; i++) {
final IndexResponse indexResponse1 = runner.insert(index, type, String.valueOf(i),
"{\"id\":\"" + i + "\",\"msg\":\"test " + i + "\",\"counter\":" + i + "}");
assertEquals(Result.CREATED, indexResponse1.getResult());
}
{
final SearchResponse searchResponse =
client.prepareSearch(index).setQuery(QueryBuilders.matchAllQuery()).addSort("counter", SortOrder.ASC)
//.putHeader("_rerank", false)
.execute().actionGet();
final SearchHits hits = searchResponse.getHits();
assertEquals(1000, hits.getTotalHits());
assertEquals(10, hits.getHits().length);
assertEquals("1", hits.getHits()[0].getId());
assertEquals("10", hits.getHits()[9].getId());
}
}
示例11: insert
import org.elasticsearch.action.DocWriteResponse.Result; //导入依赖的package包/类
public IndexResponse insert(final String index, final String type,
final String id,
final BuilderCallback<IndexRequestBuilder> builder) {
final IndexResponse actionGet = builder
.apply(client().prepareIndex(index, type, id)).execute()
.actionGet();
if (actionGet.getResult() != Result.CREATED) {
onFailure("Failed to insert " + id + " into " + index + "/" + type
+ ".", actionGet);
}
return actionGet;
}
示例12: delete
import org.elasticsearch.action.DocWriteResponse.Result; //导入依赖的package包/类
public DeleteResponse delete(final String index, final String type,
final String id,
final BuilderCallback<DeleteRequestBuilder> builder) {
final DeleteResponse actionGet = builder
.apply(client().prepareDelete(index, type, id)).execute()
.actionGet();
if (actionGet.getResult() != Result.DELETED) {
onFailure("Failed to delete " + id + " from " + index + "/" + type
+ ".", actionGet);
}
return actionGet;
}
示例13: delById
import org.elasticsearch.action.DocWriteResponse.Result; //导入依赖的package包/类
public boolean delById(String id) {
DeleteResponse response = client.prepareDelete(INDEX_NAME, TYPE_NAME, id).get();
return response.getResult() == Result.DELETED;
}
示例14: update
import org.elasticsearch.action.DocWriteResponse.Result; //导入依赖的package包/类
/**
* 更新网页
* @param page
* @return
*/
public boolean update(Webpage page) {
UpdateResponse response = client.prepareUpdate(INDEX_NAME, TYPE_NAME, page.getId())
.setDoc(GSON.toJson(page), XContentType.JSON).get();
return response.getResult() == Result.UPDATED;
}
示例15: test_japanese
import org.elasticsearch.action.DocWriteResponse.Result; //导入依赖的package包/类
@Test
public void test_japanese() throws Exception {
runner.ensureYellow();
Node node = runner.node();
final String index = "dataset";
final String type = "item";
final String indexSettings = "{\"index\":{\"analysis\":{" + "\"tokenizer\":{"//
+ "\"ja_user_dict\":{\"type\":\"fess_japanese_tokenizer\",\"mode\":\"extended\",\"user_dictionary\":\"userdict_ja.txt\"}"
+ "},"//
+ "\"analyzer\":{"
+ "\"ja_analyzer\":{\"type\":\"custom\",\"tokenizer\":\"ja_user_dict\",\"filter\":[\"fess_japanese_stemmer\"]}" + "}"//
+ "}}}";
runner.createIndex(index, Settings.builder().loadFromSource(indexSettings, XContentType.JSON).build());
// create a mapping
final XContentBuilder mappingBuilder = XContentFactory.jsonBuilder()//
.startObject()//
.startObject(type)//
.startObject("properties")//
// id
.startObject("id")//
.field("type", "keyword")//
.endObject()//
// msg1
.startObject("msg")//
.field("type", "text")//
.field("analyzer", "ja_analyzer")//
.endObject()//
.endObject()//
.endObject()//
.endObject();
runner.createMapping(index, type, mappingBuilder);
final IndexResponse indexResponse1 = runner.insert(index, type, "1", "{\"msg\":\"東京スカイツリー\", \"id\":\"1\"}");
assertEquals(Result.CREATED, indexResponse1.getResult());
runner.refresh();
assertDocCount(0, index, type, "msg", "東京スカイツリー");
try (CurlResponse response = Curl.post(node, "/" + index + "/_analyze").header("Content-Type", "application/json")
.body("{\"text\":\"東京スカイツリー\",\"analyzer\":\"ja_analyzer\"}").execute()) {
@SuppressWarnings("unchecked")
List<Map<String, Object>> tokens = (List<Map<String, Object>>) response.getContentAsMap().get("tokens");
assertEquals(0, tokens.size());
}
}