Search in sources :

Example 96 with IndexResponse

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.index.IndexResponse in project tutorials by eugenp.

the class GeoQueriesTest method givenGeoPointData_whenExecutedGeoBoundingBoxQuery_thenResultNonEmpty.

@Test
public void givenGeoPointData_whenExecutedGeoBoundingBoxQuery_thenResultNonEmpty() {
    String jsonObject = "{\"name\":\"Pyramids of Giza\",\"location\":[31.131302,29.976480]}";
    IndexResponse response = client.prepareIndex(WONDERS_OF_WORLD, WONDERS).setSource(jsonObject).get();
    String pyramidsOfGizaId = response.getId();
    client.admin().indices().prepareRefresh(WONDERS_OF_WORLD).get();
    QueryBuilder qb = QueryBuilders.geoBoundingBoxQuery("location").bottomLeft(28, 30).topRight(31, 32);
    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(pyramidsOfGizaId));
}
Also used : IndexResponse(org.elasticsearch.action.index.IndexResponse) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) SearchResponse(org.elasticsearch.action.search.SearchResponse) Test(org.junit.Test)

Example 97 with IndexResponse

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.index.IndexResponse in project arctic-sea by 52North.

the class ElasticsearchAdminHandlerIT method connectTransportMode.

@Test
public void connectTransportMode() throws InterruptedException {
    settings.setNodeConnectionMode(ElasticsearchSettingsKeys.CONNECTION_MODE_TRANSPORT_CLIENT);
    adminHandler.init();
    Map<String, Object> data = new HashMap<>();
    data.put("test", "test-string");
    IndexResponse idx = dataHandler.persist(data);
    Thread.sleep(2000);
    String ret = getEmbeddedClient().prepareGet(idx.getIndex(), idx.getType(), idx.getId()).get().getSourceAsString();
    Assert.assertNotNull(ret);
}
Also used : HashMap(java.util.HashMap) IndexResponse(org.elasticsearch.action.index.IndexResponse) ElasticsearchAwareTest(org.n52.iceland.statistics.basetests.ElasticsearchAwareTest) Test(org.junit.Test)

Example 98 with IndexResponse

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.index.IndexResponse in project arctic-sea by 52North.

the class ElasticsearchAdminHandlerIT method connectNodeMode.

@Test
public void connectNodeMode() throws Exception {
    settings.setNodeConnectionMode(ElasticsearchSettingsKeys.CONNECTION_MODE_NODE);
    adminHandler.init();
    Map<String, Object> data = new HashMap<>();
    data.put("test", "test-string");
    IndexResponse idx = dataHandler.persist(data);
    Thread.sleep(2000);
    String ret = getEmbeddedClient().prepareGet(idx.getIndex(), idx.getType(), idx.getId()).get().getSourceAsString();
    Assert.assertNotNull(ret);
}
Also used : HashMap(java.util.HashMap) IndexResponse(org.elasticsearch.action.index.IndexResponse) ElasticsearchAwareTest(org.n52.iceland.statistics.basetests.ElasticsearchAwareTest) Test(org.junit.Test)

Example 99 with IndexResponse

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.index.IndexResponse in project tutorials-java by Artister.

the class BookController method add.

@PostMapping("add/book/novel")
@ResponseBody
public ResponseEntity add(@RequestParam(name = "title") @NotBlank(message = "标题不可以为空") String title, @RequestParam(name = "author") @NotBlank(message = "作者不可以为空") String author, @RequestParam(name = "word_count") @NotBlank(message = "字数不可以为空") String wordCount, @RequestParam(name = "publish_date") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date publishDate) {
    try {
        XContentBuilder content = XContentFactory.jsonBuilder().startObject().field("title", title).field("author", author).field("word_count", wordCount).field("publish_date", publishDate).endObject();
        IndexResponse response = client.prepareIndex("book", "novel").setSource(content).get();
        return new ResponseEntity(response.getId(), HttpStatus.OK);
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) IndexResponse(org.elasticsearch.action.index.IndexResponse) IOException(java.io.IOException) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder)

Example 100 with IndexResponse

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.index.IndexResponse in project elasticsearch-graphite-plugin by spinscale.

the class GraphitePluginIntegrationTest method testThatFieldExclusionWorksWithPrefix.

@Test
public void testThatFieldExclusionWorksWithPrefix() throws Exception {
    String prefix = "my.awesome.prefix";
    String excludeRegex = prefix + ".node.[http|jvm].*";
    node = createNode(clusterName, GRAPHITE_SERVER_PORT, "1s", null, excludeRegex, prefix);
    IndexResponse indexResponse = indexElement(node, index, type, "value");
    assertThat(indexResponse.getId(), is(notNullValue()));
    Thread.sleep(2000);
    ensureValidKeyNames();
    // ensure no global exclusion
    assertGraphiteMetricIsContained(prefix + ".indexes." + index + ".id.0.indexing._all.indexCount 1");
    assertGraphiteMetricIsNotContained(prefix + ".node.jvm.threads.peakCount ");
    assertGraphiteMetricIsNotContained(prefix + ".node.http.totalOpen ");
}
Also used : IndexResponse(org.elasticsearch.action.index.IndexResponse) Test(org.junit.Test)

Aggregations

IndexResponse (org.elasticsearch.action.index.IndexResponse)108 Test (org.junit.Test)26 SearchResponse (org.elasticsearch.action.search.SearchResponse)18 IOException (java.io.IOException)17 CreateIndexResponse (org.elasticsearch.action.admin.indices.create.CreateIndexResponse)17 IndexRequest (org.elasticsearch.action.index.IndexRequest)16 HashMap (java.util.HashMap)15 DeleteResponse (org.elasticsearch.action.delete.DeleteResponse)14 ElasticsearchException (org.elasticsearch.ElasticsearchException)12 CountDownLatch (java.util.concurrent.CountDownLatch)10 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)10 Settings (org.elasticsearch.common.settings.Settings)9 BulkResponse (org.elasticsearch.action.bulk.BulkResponse)7 GetResponse (org.elasticsearch.action.get.GetResponse)7 ArrayList (java.util.ArrayList)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)6 DocWriteRequest (org.elasticsearch.action.DocWriteRequest)6 CreateIndexRequest (org.elasticsearch.action.admin.indices.create.CreateIndexRequest)6 DeleteIndexResponse (org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse)6 UpdateResponse (org.elasticsearch.action.update.UpdateResponse)6