use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.index.IndexResponse in project tutorials by eugenp.
the class ElasticSearchManualTest method givenContentBuilder_whenHelpers_thanIndexJson.
@Test
public void givenContentBuilder_whenHelpers_thanIndexJson() throws IOException {
XContentBuilder builder = XContentFactory.jsonBuilder().startObject().field("fullName", "Test").field("salary", "11500").field("age", "10").endObject();
IndexResponse response = client.prepareIndex("people", "Doe").setSource(builder).get();
assertTrue(response.isCreated());
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.index.IndexResponse in project tutorials by eugenp.
the class GeoQueriesTest method givenGeoPointData_whenExecutedGeoPolygonQuery_thenResultNonEmpty.
@Test
public void givenGeoPointData_whenExecutedGeoPolygonQuery_thenResultNonEmpty() {
String jsonObject = "{\"name\":\"The Great Rann of Kutch\",\"location\":[69.859741,23.733732]}";
IndexResponse response = client.prepareIndex(WONDERS_OF_WORLD, WONDERS).setSource(jsonObject).get();
String greatRannOfKutchid = response.getId();
client.admin().indices().prepareRefresh(WONDERS_OF_WORLD).get();
QueryBuilder qb = QueryBuilders.geoPolygonQuery("location").addPoint(22.733, 68.859).addPoint(24.733, 68.859).addPoint(23, 70.859);
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(greatRannOfKutchid));
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.index.IndexResponse in project incubator-skywalking by apache.
the class InstanceRegisterEsDAO method save.
@Override
public void save(Instance instance) {
logger.debug("save instance register info, application getApplicationId: {}, agentUUID: {}", instance.getApplicationId(), instance.getAgentUUID());
ElasticSearchClient client = getClient();
Map<String, Object> source = new HashMap<>();
source.put(InstanceTable.COLUMN_INSTANCE_ID, instance.getInstanceId());
source.put(InstanceTable.COLUMN_APPLICATION_ID, instance.getApplicationId());
source.put(InstanceTable.COLUMN_APPLICATION_CODE, instance.getApplicationCode());
source.put(InstanceTable.COLUMN_AGENT_UUID, instance.getAgentUUID());
source.put(InstanceTable.COLUMN_REGISTER_TIME, TimeBucketUtils.INSTANCE.getSecondTimeBucket(instance.getRegisterTime()));
source.put(InstanceTable.COLUMN_HEARTBEAT_TIME, TimeBucketUtils.INSTANCE.getSecondTimeBucket(instance.getHeartBeatTime()));
source.put(InstanceTable.COLUMN_OS_INFO, instance.getOsInfo());
source.put(InstanceTable.COLUMN_ADDRESS_ID, instance.getAddressId());
source.put(InstanceTable.COLUMN_IS_ADDRESS, instance.getIsAddress());
IndexResponse response = client.prepareIndex(InstanceTable.TABLE, instance.getId()).setSource(source).setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE).get();
logger.debug("save instance register info, application getApplicationId: {}, agentUUID: {}, status: {}", instance.getApplicationId(), instance.getAgentUUID(), response.status().name());
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.index.IndexResponse in project incubator-skywalking by apache.
the class ServiceNameRegisterEsDAO method save.
@Override
public void save(ServiceName serviceName) {
logger.debug("save service name register info, application getApplicationId: {}, service name: {}", serviceName.getId(), serviceName.getServiceName());
ElasticSearchClient client = getClient();
Map<String, Object> source = new HashMap<>();
source.put(ServiceNameTable.COLUMN_SERVICE_ID, serviceName.getServiceId());
source.put(ServiceNameTable.COLUMN_APPLICATION_ID, serviceName.getApplicationId());
source.put(ServiceNameTable.COLUMN_SERVICE_NAME, serviceName.getServiceName());
source.put(ServiceNameTable.COLUMN_SERVICE_NAME_KEYWORD, serviceName.getServiceName());
source.put(ServiceNameTable.COLUMN_SRC_SPAN_TYPE, serviceName.getSrcSpanType());
IndexResponse response = client.prepareIndex(ServiceNameTable.TABLE, serviceName.getId()).setSource(source).setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE).get();
logger.debug("save service name register info, application getApplicationId: {}, service name: {}, status: {}", serviceName.getId(), serviceName.getServiceName(), response.status().name());
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.index.IndexResponse in project incubator-skywalking by apache.
the class NetworkAddressRegisterEsDAO method save.
@Override
public void save(NetworkAddress networkAddress) {
logger.debug("save network address register info, address getApplicationId: {}, network address code: {}", networkAddress.getId(), networkAddress.getNetworkAddress());
ElasticSearchClient client = getClient();
Map<String, Object> source = new HashMap<>();
source.put(NetworkAddressTable.COLUMN_NETWORK_ADDRESS, networkAddress.getNetworkAddress());
source.put(NetworkAddressTable.COLUMN_ADDRESS_ID, networkAddress.getAddressId());
source.put(NetworkAddressTable.COLUMN_SPAN_LAYER, networkAddress.getSpanLayer());
source.put(NetworkAddressTable.COLUMN_SERVER_TYPE, networkAddress.getServerType());
IndexResponse response = client.prepareIndex(NetworkAddressTable.TABLE, networkAddress.getId()).setSource(source).setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE).get();
logger.debug("save network address register info, address getApplicationId: {}, network address code: {}, status: {}", networkAddress.getAddressId(), networkAddress.getNetworkAddress(), response.status().name());
}
Aggregations