本文整理汇总了Java中org.codelibs.elasticsearch.runner.net.Curl类的典型用法代码示例。如果您正苦于以下问题:Java Curl类的具体用法?Java Curl怎么用?Java Curl使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Curl类属于org.codelibs.elasticsearch.runner.net包,在下文中一共展示了Curl类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: waitForNdocs
import org.codelibs.elasticsearch.runner.net.Curl; //导入依赖的package包/类
private void waitForNdocs(final Node node, final String index1, final String type, final long num) throws Exception {
long actual = 0;
for (int i = 0; i < 30; i++) {
try (CurlResponse curlResponse = Curl.post(node, "/" + index1 + "/" + type + "/_search")
.header("Content-Type", "application/json").body("{\"query\":{\"match_all\":{}}}").execute()) {
final Map<String, Object> map = curlResponse.getContentAsMap();
@SuppressWarnings("unchecked")
final Map<String, Object> hits = (Map<String, Object>) map.get("hits");
actual = ((Number) hits.get("total")).longValue();
if (actual == num) {
Thread.sleep(3000L); // wait for bulk requests
return;
}
}
runner.refresh();
Thread.sleep(1000L);
}
fail(num + " docs are not inserted. " + actual + " docs exist.");
}
示例2: bulkRequest
import org.codelibs.elasticsearch.runner.net.Curl; //导入依赖的package包/类
private void bulkRequest(final Node node, final String index, final String type, final long id) throws IOException {
final StringBuilder buf = new StringBuilder();
long value = id;
buf.append("{\"create\":{\"_index\":\"" + index + "\",\"_type\":\"" + type + "\",\"_id\":\"" + value + "\"}}\n");
buf.append("{\"id\":" + value + ",\"msg\":\"test " + value + "\"}\n");
value++;
createRequest(node, index, type, value);
buf.append("{\"update\":{\"_index\":\"" + index + "\",\"_type\":\"" + type + "\",\"_id\":\"" + value + "\"}}\n");
buf.append("{\"doc\":{\"msg\":\"test " + (value + 300) + "\"}}\n");
value++;
createRequest(node, index, type, value);
buf.append("{\"delete\":{\"_index\":\"" + index + "\",\"_type\":\"" + type + "\",\"_id\":\"" + value + "\"}}\n");
try (CurlResponse curlResponse =
Curl.post(node, "/_bulk").header("Content-Type", "application/x-ndjson").body(buf.toString()).execute()) {
final Map<String, Object> map = curlResponse.getContentAsMap();
assertNotNull(map);
assertTrue(map.containsKey("took"));
}
}
示例3: test_wait_for_completion
import org.codelibs.elasticsearch.runner.net.Curl; //导入依赖的package包/类
private void test_wait_for_completion(Node node, String index) {
String newIndex0 = "dataset0", newIndex1 = "dataset1";
CurlResponse response0 = Curl.post(node, "/" + index + "/_reindex/" + newIndex0)
.param("wait_for_completion", "true").execute();
CurlResponse response1 = Curl.post(node, "/" + index + "/_reindex/" + newIndex1)
.execute();
Map<String, Object> map0 = response0.getContentAsMap();
Map<String, Object> map1 = response1.getContentAsMap();
assertEquals(map0.size(), 1);
assertTrue(map0.containsKey("acknowledged"));
assertEquals(map1.size(), 2);
assertTrue(map1.containsKey("acknowledged"));
assertTrue(map1.containsKey("name"));
runner.flush();
runner.deleteIndex(newIndex0);
runner.deleteIndex(newIndex1);
}
示例4: test_render
import org.codelibs.elasticsearch.runner.net.Curl; //导入依赖的package包/类
@Test
public void test_render() throws Exception {
setupEs();
assertThat(1, is(runner.getNodeSize()));
final Node node = runner.node();
try (CurlResponse curlResponse = Curl.post(node, "/_search/script_template/velocity/index_search_query_1").body(
"{\"template\":\"{\\\"query\\\":{\\\"match\\\":{\\\"${my_field}\\\":\\\"${my_value}\\\"}},\\\"size\\\":\\\"${my_size}\\\"}\"}")
.execute()) {
assertThat(200, is(curlResponse.getHttpStatusCode()));
}
String query;
query = "{\"lang\":\"velocity\",\"inline\":\"{\\\"query\\\":{\\\"match\\\":{\\\"$my_field\\\":\\\"$my_value\\\"}},\\\"size\\\":\\\"$my_size\\\"}\","
+ "\"params\":{\"my_field\":\"category\",\"my_value\":\"1\",\"my_size\":\"50\"}}";
try (CurlResponse curlResponse = Curl.post(node, "/_render/script_template").body(query).execute()) {
final String content = curlResponse.getContentAsString();
assertEquals("{\"template_output\":{\"query\":{\"match\":{\"category\":\"1\"}},\"size\":\"50\"}}", content);
}
}
示例5: assertSender
import org.codelibs.elasticsearch.runner.net.Curl; //导入依赖的package包/类
private void assertSender(final Node node, final String index, final boolean found, final boolean running) throws IOException {
try (CurlResponse curlResponse =
Curl.get(node, "/" + index + "/_idxproxy/process").header("Content-Type", "application/json").execute()) {
final Map<String, Object> map = curlResponse.getContentAsMap();
assertNotNull(map);
assertEquals(found, ((Boolean) map.get("found")).booleanValue());
if (found) {
assertEquals(running, ((Boolean) map.get("running")).booleanValue());
}
}
}
示例6: assertNumOfDocs
import org.codelibs.elasticsearch.runner.net.Curl; //导入依赖的package包/类
private void assertNumOfDocs(final Node node1, final String index1, final String type, final long total) throws IOException {
try (CurlResponse curlResponse = Curl.post(node1, "/" + index1 + "/" + type + "/_search").header("Content-Type", "application/json")
.body("{\"query\":{\"match_all\":{}}}").execute()) {
final Map<String, Object> map = curlResponse.getContentAsMap();
assertNotNull(map);
@SuppressWarnings("unchecked")
final Map<String, Object> hits = (Map<String, Object>) map.get("hits");
assertEquals(total, ((Number) hits.get("total")).longValue());
}
}
示例7: assertFilePosition
import org.codelibs.elasticsearch.runner.net.Curl; //导入依赖的package包/类
private void assertFilePosition(final Node node, final String index, final int position) throws IOException {
try (CurlResponse curlResponse =
Curl.get(node, "/.idxproxy/config/" + index).header("Content-Type", "application/json").execute()) {
final Map<String, Object> map = curlResponse.getContentAsMap();
assertNotNull(map);
@SuppressWarnings("unchecked")
final Map<String, Object> source = (Map<String, Object>) map.get("_source");
assertEquals(position, ((Number) source.get("file_position")).longValue());
}
}
示例8: deleteByQueryRequest
import org.codelibs.elasticsearch.runner.net.Curl; //导入依赖的package包/类
private void deleteByQueryRequest(final Node node, final String index, final String type, final long id) throws IOException {
try (CurlResponse curlResponse = Curl.post(node, "/" + index + "/" + type + "/_delete_by_query")
.header("Content-Type", "application/json").body("{\"query\":{\"term\":{\"id\":" + id + "}}}").execute()) {
final Map<String, Object> map = curlResponse.getContentAsMap();
assertNotNull(map);
assertTrue(map.containsKey("took"));
}
}
示例9: deleteRequest
import org.codelibs.elasticsearch.runner.net.Curl; //导入依赖的package包/类
private void deleteRequest(final Node node, final String index, final String type, final long id) throws IOException {
try (CurlResponse curlResponse =
Curl.delete(node, "/" + index + "/" + type + "/" + id).header("Content-Type", "application/json").execute()) {
final Map<String, Object> map = curlResponse.getContentAsMap();
assertNotNull(map);
assertEquals("true", map.get("found").toString());
}
}
示例10: updateByQueryRequest
import org.codelibs.elasticsearch.runner.net.Curl; //导入依赖的package包/类
private void updateByQueryRequest(final Node node, final String index, final String type, final long id) throws IOException {
try (CurlResponse curlResponse = Curl.post(node, "/" + index + "/" + type + "/_update_by_query")
.header("Content-Type", "application/json").body("{\"script\":{\"inline\":\"ctx._source.msg='test " + (id + 200)
+ "'\",\"lang\":\"painless\"},\"query\":{\"term\":{\"id\":" + id + "}}}")
.execute()) {
final Map<String, Object> map = curlResponse.getContentAsMap();
assertNotNull(map);
assertTrue(map.containsKey("took"));
}
}
示例11: updateRequest
import org.codelibs.elasticsearch.runner.net.Curl; //导入依赖的package包/类
private void updateRequest(final Node node, final String index, final String type, final long id) throws IOException {
try (CurlResponse curlResponse = Curl.post(node, "/" + index + "/" + type + "/" + id + "/_update")
.header("Content-Type", "application/json").body("{\"doc\":{\"msg\":\"test " + (id + 100) + "\"}}").execute()) {
final Map<String, Object> map = curlResponse.getContentAsMap();
assertNotNull(map);
assertTrue(map.containsKey("result"));
}
}
示例12: createRequest
import org.codelibs.elasticsearch.runner.net.Curl; //导入依赖的package包/类
private void createRequest(final Node node, final String index, final String type, final long id) throws IOException {
try (CurlResponse curlResponse = Curl.put(node, "/" + index + "/" + type + "/" + id).header("Content-Type", "application/json")
.param("refresh", "true").body("{\"id\":" + id + ",\"msg\":\"test " + id + "\"}").execute()) {
final Map<String, Object> map = curlResponse.getContentAsMap();
assertNotNull(map);
assertEquals("true", map.get("created").toString());
}
}
示例13: indexRequest
import org.codelibs.elasticsearch.runner.net.Curl; //导入依赖的package包/类
private void indexRequest(final Node node, final String index, final String type, final long id) throws IOException {
try (CurlResponse curlResponse = Curl.post(node, "/" + index + "/" + type).header("Content-Type", "application/json")
.param("refresh", "true").body("{\"id\":" + id + ",\"msg\":\"test " + id + "\"}").execute()) {
final Map<String, Object> map = curlResponse.getContentAsMap();
assertNotNull(map);
assertEquals("true", map.get("created").toString());
}
}
示例14: test_step1
import org.codelibs.elasticsearch.runner.net.Curl; //导入依赖的package包/类
@Test
public void test_step1() throws Exception {
runner.ensureYellow();
Node node = runner.node();
final String index = "dataset";
final String indexSettings = "{\"index\":{\"analysis\":{" + "\"filter\":{"
+ "\"stem1_filter\":{\"type\":\"flexible_porter_stem\",\"step1\":true,\"step2\":false,\"step3\":false,\"step4\":false,\"step5\":false,\"step6\":false}"
+ "},"//
+ "\"analyzer\":{" + "\"default_analyzer\":{\"type\":\"custom\",\"tokenizer\":\"whitespace\"},"
+ "\"stem1_analyzer\":{\"type\":\"custom\",\"tokenizer\":\"whitespace\",\"filter\":[\"stem1_filter\"]}" + "}"//
+ "}}}";
runner.createIndex(index, Settings.builder().loadFromSource(indexSettings, XContentType.JSON).build());
runner.ensureYellow();
{
String text = "consist consisted consistency consistent consistently consisting consists";
try (CurlResponse response = Curl.post(node, "/" + index + "/_analyze").header("Content-Type", "application/json")
.body("{\"analyzer\":\"stem1_analyzer\",\"text\":\"" + text + "\"}").execute()) {
@SuppressWarnings("unchecked")
List<Map<String, Object>> tokens = (List<Map<String, Object>>) response.getContentAsMap().get("tokens");
assertEquals(7, tokens.size());
assertEquals("consist", tokens.get(0).get("token").toString());
assertEquals("consist", tokens.get(1).get("token").toString());
assertEquals("consistency", tokens.get(2).get("token").toString());
assertEquals("consistent", tokens.get(3).get("token").toString());
assertEquals("consistently", tokens.get(4).get("token").toString());
assertEquals("consist", tokens.get(5).get("token").toString());
assertEquals("consist", tokens.get(6).get("token").toString());
}
}
}
示例15: test_basic
import org.codelibs.elasticsearch.runner.net.Curl; //导入依赖的package包/类
@Test
public void test_basic() throws Exception {
numberSuffixFiles = new File[numOfNode];
for (int i = 0; i < numOfNode; i++) {
String homePath = runner.getNode(i).settings().get("path.home");
numberSuffixFiles[i] = new File(new File(homePath, "config"), "tags.txt");
updateDictionary(numberSuffixFiles[i], "名詞-形容動詞語幹\n名詞-サ変接続");
}
runner.ensureYellow();
Node node = runner.node();
final String index = "dataset";
final String indexSettings = "{\"index\":{\"analysis\":{"
+ "\"filter\":{"
+ "\"tag_concat_filter\":{\"type\":\"kuromoji_pos_concat\",\"tags_path\":\"tags.txt\"}"
+ "},"//
+ "\"analyzer\":{"
+ "\"ja_analyzer\":{\"type\":\"custom\",\"tokenizer\":\"reloadable_kuromoji_tokenizer\"},"
+ "\"ja_concat_analyzer\":{\"type\":\"custom\",\"tokenizer\":\"reloadable_kuromoji_tokenizer\",\"filter\":[\"tag_concat_filter\"]}"
+ "}"//
+ "}}}";
runner.createIndex(index, Settings.builder().loadFromSource(indexSettings, XContentType.JSON).build());
runner.ensureYellow();
{
String text = "詳細設計";
try (CurlResponse response = Curl.post(node, "/" + index + "/_analyze").header("Content-Type", "application/json")
.body("{\"analyzer\":\"ja_concat_analyzer\",\"text\":\"" + text + "\"}").execute()) {
@SuppressWarnings("unchecked")
List<Map<String, Object>> tokens = (List<Map<String, Object>>) response
.getContentAsMap().get("tokens");
assertEquals(1, tokens.size());
assertEquals("詳細設計", tokens.get(0).get("token").toString());
}
}
}