diff --git a/README.md b/README.md
index 98a81f0..9d1b93b 100644
--- a/README.md
+++ b/README.md
@@ -4,7 +4,7 @@ Elasticsearch Data Format Plugin
## Overview
Elasticsearch Data Format Plugin provides a feature to allow you to download a response of a search result as several formats other than JSON.
-The supported formats are CSV, Excel, JSON(Bulk), JSON(Object List) and GeoJSON.
+The supported formats are CSV, Excel, JSON(Bulk) and JSON(Object List).
## Version
@@ -31,7 +31,7 @@ If not, it's as scan query(all data are stored.).
| Request Parameter | Type | Description |
|:------------------|:-------:|:------------|
| append.header | boolean | Append column headers if true |
-| fields_name | string | choose the fields to dump (comma separate format) |
+| fields_name | string | choose the fields to dump |
| source | string | [Query DSL](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl.html) |
| csv.separator | string | Separate character in CSV |
| csv.quote | string | Quote character in CSV|
@@ -46,7 +46,7 @@ If not, it's as scan query(all data are stored.).
| Request Parameter | Type | Description |
|:------------------|:-------:|:------------|
| append.header | boolean | Append column headers if true |
-| fields_name | string | choose the fields to dump (comma separate format) |
+| fields_name | string | choose the fields to dump |
| source | string | [Query DSL](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl.html) |
### Excel 2007
@@ -55,8 +55,6 @@ If not, it's as scan query(all data are stored.).
| Request Parameter | Type | Description |
|:------------------|:-------:|:------------|
-| append.header | boolean | Append column headers if true |
-| fields_name | string | choose the fields to dump (comma separate format) |
| source | string | [Query DSL](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl.html) |
### JSON (Elasticsearch Bulk format)
@@ -77,19 +75,3 @@ If not, it's as scan query(all data are stored.).
| :---------------- | :----: | :----------------------------------------------------------- |
| source | string | [Query DSL](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl.html) |
-### GeoJSON (Open GIS standard)
-
- $ curl -o /tmp/data.json -XGET "localhost:9200/{index}/{type}/_data?format=geojson&source=..."
-
-| Request Parameter | Type | Description |
-| :----------------------- | :----: | :----------------------------------------------------------- |
-| source | string | [Query DSL](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl.html) |
-| geometry.lon_field | string | Longitude field for coordinates (Support Geometry type "Point") |
-| geometry.lat_field | string | Latitude field for coordinates (Support Geometry type "Point") |
-| geometry.alt_field | string | Altitude field for coordinates (Support Geometry type "Point") |
-| geometry.coord_field | string | Coordinates field. Support all Geometry types (see [GeoJSON Example](https://en.wikipedia.org/wiki/GeoJSON)).
If set, overwrite `geometry.lon_field`, `geometry.lat_field` and `geometry.alt_field` |
-| geometry.type_field | string | Geometry type field (see [GeoJSON Example](https://en.wikipedia.org/wiki/GeoJSON))
Only used if `geometry.coord_field` param is set |
-| keep_geometry_info | boolean | Keep or not the original geometry fields in final GeoJSON properties (default: false) |
-| exclude_fields | string | Exclude fields in final geojson properties (comma separate format) |
-
-**NB**: Field name can use basic style like `a` or JSONpath style like `a.b.c[2].d`
diff --git a/pom.xml b/pom.xml
index a6a98b6..a742b94 100644
--- a/pom.xml
+++ b/pom.xml
@@ -121,11 +121,6 @@
poi-ooxml-schemas
${poi.version}
-
- com.google.code.gson
- gson
- 2.8.6
-
org.codelibs
elasticsearch-cluster-runner
diff --git a/src/main/java/org/codelibs/elasticsearch/df/content/ContentType.java b/src/main/java/org/codelibs/elasticsearch/df/content/ContentType.java
index bfb1306..8554dfb 100644
--- a/src/main/java/org/codelibs/elasticsearch/df/content/ContentType.java
+++ b/src/main/java/org/codelibs/elasticsearch/df/content/ContentType.java
@@ -1,7 +1,6 @@
package org.codelibs.elasticsearch.df.content;
import org.codelibs.elasticsearch.df.content.csv.CsvContent;
-import org.codelibs.elasticsearch.df.content.geojson.GeoJsonContent;
import org.codelibs.elasticsearch.df.content.json.JsonContent;
import org.codelibs.elasticsearch.df.content.json.JsonListContent;
import org.codelibs.elasticsearch.df.content.xls.XlsContent;
@@ -118,27 +117,6 @@ public String fileName(final RestRequest request) {
}
return index + ".json";
}
- },
- GEOJSON(60) {
- @Override
- public String contentType() {
- return "application/geo+json";
- }
-
- @Override
- public DataContent dataContent(final Client client,
- final RestRequest request) {
- return new GeoJsonContent(client, request, this);
- }
-
- @Override
- public String fileName(final RestRequest request) {
- final String index = request.param("index");
- if (index == null) {
- return "_all.geojson";
- }
- return index + ".geojson";
- }
};
private int index;
diff --git a/src/main/java/org/codelibs/elasticsearch/df/content/geojson/GeoJsonContent.java b/src/main/java/org/codelibs/elasticsearch/df/content/geojson/GeoJsonContent.java
deleted file mode 100644
index a503c6d..0000000
--- a/src/main/java/org/codelibs/elasticsearch/df/content/geojson/GeoJsonContent.java
+++ /dev/null
@@ -1,240 +0,0 @@
-package org.codelibs.elasticsearch.df.content.geojson;
-
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.OutputStreamWriter;
-import java.io.Writer;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-import org.codelibs.elasticsearch.df.content.ContentType;
-import org.codelibs.elasticsearch.df.content.DataContent;
-import org.codelibs.elasticsearch.df.util.JsonUtils;
-import org.codelibs.elasticsearch.df.util.RequestUtil;
-import org.codelibs.elasticsearch.df.util.StringUtils;
-import org.elasticsearch.ElasticsearchException;
-import org.elasticsearch.action.ActionListener;
-import org.elasticsearch.action.search.SearchResponse;
-import org.elasticsearch.client.Client;
-import org.elasticsearch.common.xcontent.XContentHelper;
-import org.elasticsearch.common.xcontent.XContentType;
-import org.elasticsearch.rest.RestChannel;
-import org.elasticsearch.rest.RestRequest;
-import org.elasticsearch.search.SearchHit;
-import org.elasticsearch.search.SearchHits;
-
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
-import com.google.gson.JsonArray;
-import com.google.gson.JsonElement;
-import com.google.gson.JsonObject;
-import com.google.gson.JsonParser;
-
-public class GeoJsonContent extends DataContent {
- private static final Logger logger = LogManager.getLogger(GeoJsonContent.class);
-
- private final String geometryCoordinatesLonField;
- private final String geometryCoordinatesLatField;
- private final String geometryCoordinatesAltField;
- private final String geometryTypeField;
- private final String geometryCoordinatesField;
- private final boolean geometryKeepGeoInfo;
- private final List excludeFields;
-
- public GeoJsonContent(final Client client, final RestRequest request, final ContentType contentType) {
- super(client, request, contentType);
-
- geometryCoordinatesLonField = request.param("geometry.lon_field",StringUtils.EMPTY_STRING);
- geometryCoordinatesLatField = request.param("geometry.lat_field",StringUtils.EMPTY_STRING);
- geometryCoordinatesAltField = request.param("geometry.alt_field",StringUtils.EMPTY_STRING);
- geometryTypeField = request.param("geometry.type_field",StringUtils.EMPTY_STRING);
- geometryCoordinatesField = request.param("geometry.coord_field",StringUtils.EMPTY_STRING);
- geometryKeepGeoInfo = request.paramAsBoolean("keep_geometry_info",false);
-
- final String[] fields = request.paramAsStringArray("exclude_fields", StringUtils.EMPTY_STRINGS);
- if (fields.length == 0) {
- excludeFields = new ArrayList<>();
- } else {
- final List fieldList = new ArrayList<>();
- for (final String field : fields) {
- fieldList.add(field.trim());
- }
- excludeFields = Collections.unmodifiableList(fieldList);
- }
-
- if (logger.isDebugEnabled()) {
- logger.debug("geometryTypeField: {}, geometryCoordinatesField: {}, geometryCoordinatesLonField: {}, " +
- "geometryCoordinatesLatField: {}, geometryCoordinatesAltField: {}, geometryKeepGeoInfo: {}, excludeFields: {}",
- geometryTypeField, geometryCoordinatesField, geometryCoordinatesLonField,
- geometryCoordinatesLatField, geometryCoordinatesAltField, geometryKeepGeoInfo, excludeFields);
- }
- }
-
- @Override
- public void write(final File outputFile, final SearchResponse response, final RestChannel channel,
- final ActionListener listener) {
- try {
- final OnLoadListener onLoadListener = new OnLoadListener(
- outputFile, listener);
- onLoadListener.onResponse(response);
- } catch (final Exception e) {
- listener.onFailure(new ElasticsearchException("Failed to write data.",
- e));
- }
- }
-
- protected class OnLoadListener implements ActionListener {
- protected ActionListener listener;
-
- protected Writer writer;
-
- protected File outputFile;
-
- private long currentCount = 0;
-
- private boolean firstLine = true;
-
- protected OnLoadListener(final File outputFile, final ActionListener listener) {
- this.outputFile = outputFile;
- this.listener = listener;
- try {
- writer = new BufferedWriter(new OutputStreamWriter(
- new FileOutputStream(outputFile), "UTF-8"));
- } catch (final Exception e) {
- throw new ElasticsearchException("Could not open "
- + outputFile.getAbsolutePath(), e);
- }
- try {
- writer.append("{\"type\": \"FeatureCollection\", \"features\": [");
- }catch (final Exception e) {
- onFailure(e);
- }
- }
-
- @Override
- public void onResponse(final SearchResponse response) {
- final Gson gsonWriter = new GsonBuilder().create();
- final String scrollId = response.getScrollId();
- final SearchHits hits = response.getHits();
- final int size = hits.getHits().length;
- currentCount += size;
- if (logger.isDebugEnabled()) {
- logger.debug("scrollId: {}, totalHits: {}, hits: {}, current: {}",
- scrollId, hits.getTotalHits(), size, currentCount);
- }
- try {
- for (final SearchHit hit : hits) {
- final String source = XContentHelper.convertToJson(
- hit.getSourceRef(), true, false, XContentType.JSON);
- if (!firstLine){
- writer.append(',');
- }else{
- firstLine = false;
- }
-
- final JsonElement propertiesJson = JsonParser.parseString(source);
- String geometryType = "";
-
- JsonArray geometryCoordinates = new JsonArray();
- if (!geometryCoordinatesField.isEmpty()){
- JsonElement jsonEltCoord = JsonUtils.getJsonElement(propertiesJson,geometryCoordinatesField);
- if (jsonEltCoord !=null && !jsonEltCoord.isJsonNull()){
- geometryCoordinates = jsonEltCoord.getAsJsonArray​();
- if (!geometryKeepGeoInfo){
- JsonUtils.removeJsonElement(propertiesJson,geometryCoordinatesField);
- }
- }
- if (!geometryTypeField.isEmpty()){
- JsonElement jsonEltType = JsonUtils.getJsonElement(propertiesJson,geometryTypeField);
- if (jsonEltType !=null && !jsonEltType.isJsonNull()){
- geometryType = jsonEltType.getAsString();
- if (!geometryKeepGeoInfo){
- JsonUtils.removeJsonElement(propertiesJson,geometryTypeField);
- }
- }
- }
- }else{
- if (!geometryCoordinatesLonField.isEmpty() && !geometryCoordinatesLatField.isEmpty()){
- JsonElement jsonEltLon = JsonUtils.getJsonElement(propertiesJson,geometryCoordinatesLonField);
- JsonElement jsonEltLat = JsonUtils.getJsonElement(propertiesJson,geometryCoordinatesLatField);
- if (jsonEltLon !=null && !jsonEltLon.isJsonNull() && jsonEltLat !=null && !jsonEltLat.isJsonNull()){
- geometryCoordinates.add(jsonEltLon.getAsNumber());
- geometryCoordinates.add(jsonEltLat.getAsNumber());
- if (!geometryKeepGeoInfo) {
- JsonUtils.removeJsonElement(propertiesJson,geometryCoordinatesLonField);
- JsonUtils.removeJsonElement(propertiesJson,geometryCoordinatesLatField);
- }
- }
- }
- if (!geometryCoordinatesAltField.isEmpty()){
- JsonElement jsonElt = JsonUtils.getJsonElement(propertiesJson,geometryCoordinatesAltField);
- if (jsonElt !=null && !jsonElt.isJsonNull()){
- geometryCoordinates.add(jsonElt.getAsNumber());
- if (!geometryKeepGeoInfo) {
- JsonUtils.removeJsonElement(propertiesJson,geometryCoordinatesAltField);
- }
- }
- }
- geometryType = "Point";
- }
-
- for (String excludeField : excludeFields) {
- JsonUtils.removeJsonElement(propertiesJson,excludeField);
- }
-
- JsonObject geometryObject = new JsonObject();
- geometryObject.addProperty("type", geometryType);
- geometryObject.add("coordinates", geometryCoordinates);
-
- JsonObject featureObject = new JsonObject();
- featureObject.addProperty("type", "Feature");
- featureObject.add("geometry", geometryObject);
- featureObject.add("properties", propertiesJson.getAsJsonObject());
-
- writer.append('\n').append(gsonWriter.toJson(featureObject));
- }
-
- if (size == 0 || scrollId == null) {
- // end
- writer.append('\n').append("]}");
- writer.flush();
- close();
- listener.onResponse(null);
- } else {
- client.prepareSearchScroll(scrollId)
- .setScroll(RequestUtil.getScroll(request))
- .execute(this);
- }
- } catch (final Exception e) {
- onFailure(e);
- }
- }
-
- @Override
- public void onFailure(final Exception e) {
- try {
- close();
- } catch (final Exception e1) {
- // ignore
- }
- listener.onFailure(new ElasticsearchException("Failed to write data.",
- e));
- }
-
- private void close() {
- if (writer != null) {
- try {
- writer.close();
- } catch (final IOException e) {
- throw new ElasticsearchException("Could not close "
- + outputFile.getAbsolutePath(), e);
- }
- }
- }
- }
-}
diff --git a/src/main/java/org/codelibs/elasticsearch/df/rest/RestDataAction.java b/src/main/java/org/codelibs/elasticsearch/df/rest/RestDataAction.java
index e8b4a3e..e8dea2d 100644
--- a/src/main/java/org/codelibs/elasticsearch/df/rest/RestDataAction.java
+++ b/src/main/java/org/codelibs/elasticsearch/df/rest/RestDataAction.java
@@ -132,10 +132,6 @@ private ContentType getContentType(final RestRequest request) {
} else if ("application/list+json".equals(contentType)
|| "jsonlist".equals(contentType)) {
return ContentType.JSONLIST;
- } else if ("application/geo+json".equals(contentType)
- || "application/geojson".equals(contentType)
- || "geojson".equals(contentType)) {
- return ContentType.GEOJSON;
}
return null;
diff --git a/src/main/java/org/codelibs/elasticsearch/df/util/JsonUtils.java b/src/main/java/org/codelibs/elasticsearch/df/util/JsonUtils.java
deleted file mode 100644
index 7a1d9a3..0000000
--- a/src/main/java/org/codelibs/elasticsearch/df/util/JsonUtils.java
+++ /dev/null
@@ -1,96 +0,0 @@
-package org.codelibs.elasticsearch.df.util;
-
-import com.google.gson.JsonArray;
-import com.google.gson.JsonElement;
-import com.google.gson.JsonObject;
-import com.google.gson.JsonNull;
-
-public class JsonUtils {
- private JsonUtils() {
- }
-
- /**
- * Returns a JSON sub-element from the given JsonElement and the given path
- *
- * @param json - a Gson JsonElement
- * @param path - a JSON path, e.g. a.b.c[2].d
- * @return - a sub-element of json according to the given path
- */
- public static JsonElement getJsonElement(JsonElement json, String path){
-
- String[] parts = path.split("\\.|\\[|\\]");
- JsonElement result = json;
-
- for (String key : parts) {
-
- key = key.trim();
- if (key.isEmpty())
- continue;
-
- if (result == null){
- result = JsonNull.INSTANCE;
- break;
- }
-
- if (result.isJsonObject()){
- result = result.getAsJsonObject().get(key);
- }
- else if (result.isJsonArray()){
- int ix = Integer.valueOf(key);
- result = (ix < result.getAsJsonArray().size())?result.getAsJsonArray().get(ix):null;
- }
- else{
- break;
- }
- }
-
- return result;
- }
-
- /**
- * Returns a removed JSON sub-element from the given JsonElement and the given path
- *
- * @param json - a Gson JsonElement
- * @param path - a JSON path, e.g. a.b.c[2].d
- * @return - a removed sub-element of json according to the given path
- */
- public static JsonElement removeJsonElement(JsonElement json, String path){
-
- String[] parts = path.split("\\.|\\[|\\]");
- JsonElement result = json;
-
- for (int i = 0; i < parts.length; i++) {
-
- String key = parts[i].trim();
- if (key.isEmpty())
- continue;
-
- if (result == null){
- result = JsonNull.INSTANCE;
- break;
- }
-
- boolean lastPart = (i == parts.length-1);
- if (result.isJsonObject()){
- if (lastPart){
- result = result.getAsJsonObject().remove(key);
- }else{
- result = result.getAsJsonObject().get(key);
- }
- }
- else if (result.isJsonArray()){
- int ix = Integer.valueOf(key);
- if (lastPart){
- result = result.getAsJsonArray().remove(ix);
- }else{
- result = result.getAsJsonArray().get(ix);
- }
- }
- else{
- break;
- }
- }
-
- return result;
- }
-}
diff --git a/src/test/java/org/codelibs/elasticsearch/df/DataFormatPluginTest.java b/src/test/java/org/codelibs/elasticsearch/df/DataFormatPluginTest.java
index 3b244d4..c405011 100644
--- a/src/test/java/org/codelibs/elasticsearch/df/DataFormatPluginTest.java
+++ b/src/test/java/org/codelibs/elasticsearch/df/DataFormatPluginTest.java
@@ -13,7 +13,6 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.Random;
import org.apache.commons.codec.Charsets;
import org.apache.poi.hssf.usermodel.HSSFRow;
@@ -54,15 +53,12 @@ public class DataFormatPluginTest {
private static final File xlsTempFile;
private static final File jsonTempFile;
private static final File jsonListTempFile;
- private static final File geojsonTempFile;
private static final String path;
- private static final String pathgeo;
private final Map paramsCsv = new HashMap<>();
private final Map paramsXls = new HashMap<>();
private final Map paramsJson = new HashMap<>();
private final Map paramsJsonList = new HashMap<>();
- private final Map paramsGeoJson = new HashMap<>();
static {
docNumber = 20;
@@ -71,9 +67,7 @@ public class DataFormatPluginTest {
xlsTempFile = createTempFile("xlstest", ".xls");
jsonTempFile = createTempFile("jsontest", ".json");
jsonListTempFile = createTempFile("jsonlisttest", ".json");
- geojsonTempFile = createTempFile("geojsontest", ".geojson");
path = "/dataset0/_data";
- pathgeo = "/dataset1/_data";
}
@BeforeClass
@@ -116,7 +110,6 @@ public void prepareParams() {
paramsXls.put("format", "xls");
paramsJson.put("format", "json");
paramsJsonList.put("format", "jsonlist");
- paramsGeoJson.put("format", "geojson");
}
@After
@@ -125,7 +118,6 @@ public void clearParams() {
paramsXls.clear();
paramsJson.clear();
paramsJsonList.clear();
- paramsGeoJson.clear();
}
@Test
@@ -515,7 +507,7 @@ public void dumpJsonList() throws IOException {
assertEquals(docNumber + 2, lines.length);
assertTrue(lines[0].equals("["));
assertTrue(lines[1].startsWith("{" + "\"aaa\":\"test"));
- assertTrue(lines[docNumber + 1].equals("]"));
+ assertTrue(lines[docNumber + 1].equals("]"));
}
}
@@ -534,124 +526,6 @@ public void dumpJsonListInFile() throws IOException {
}
}
- @Test
- public void dumpGeoJson() throws IOException {
-
- // default call
- try (CurlResponse curlResponse = EcrCurl.get(node, "/dataset1/_data")
- .header("Content-Type", "application/json")
- .param("format", "geojson").execute()) {
- final String content = curlResponse.getContentAsString();
- final String[] lines = content.split("\n");
- assertEquals(docNumber + 2, lines.length);
- assertTrue(lines[0].equals("{\"type\": \"FeatureCollection\", \"features\": ["));
- assertTrue(lines[docNumber + 1].equals("]}"));
- }
-
- // normal call with lon_field" and "lat_field"
- try (CurlResponse curlResponse = EcrCurl.get(node, "/dataset1/_data")
- .header("Content-Type", "application/json")
- .param("format", "geojson")
- .param("geometry.lon_field", "x_lon")
- .param("geometry.lat_field", "x_lat")
- .execute()) {
- final String content = curlResponse.getContentAsString();
- final String[] lines = content.split("\n");
- assertTrue(!lines[1].contains("\"x_lon\":"));
- assertTrue(!lines[1].contains("\"x_lat\":"));
- assertTrue(lines[1].matches("(.+)\"geometry\":\\{\"type\":\"Point\",\"coordinates\":\\[[0-9\\.\\-]+,[0-9\\.\\-]+\\](.+)"));
- }
-
- // normal call with lon_field", "lat_field" and "x_alt" but without field cleaning
- try (CurlResponse curlResponse = EcrCurl.get(node, "/dataset1/_data")
- .header("Content-Type", "application/json")
- .param("format", "geojson")
- .param("geometry.lon_field", "x_lon")
- .param("geometry.lat_field", "x_lat")
- .param("geometry.alt_field", "x_alt")
- .param("keep_geometry_info", "true")
- .execute()) {
- final String content = curlResponse.getContentAsString();
- final String[] lines = content.split("\n");
- assertTrue(lines[1].contains("\"x_lon\":"));
- assertTrue(lines[1].contains("\"x_lat\":"));
- assertTrue(lines[1].contains("\"x_alt\":"));
- assertTrue(lines[1].matches("(.+)\"geometry\":\\{\"type\":\"Point\",\"coordinates\":\\[[0-9\\.\\-]+,[0-9\\.\\-]+,[0-9\\.\\-]+\\](.+)"));
- }
-
- // Look for "geometry.alt_field" value in the iii sub-object and exclude unnecessary fields from final properties
- try (CurlResponse curlResponse = EcrCurl.get(node, "/dataset1/_data")
- .header("Content-Type", "application/json")
- .param("format", "geojson")
- .param("geometry.lon_field", "x_lon")
- .param("geometry.lat_field", "x_lat")
- .param("geometry.alt_field", "iii.x_altSub")
- .param("exclude_fields", "iii,x_alt,x_coord,x_type,x_typeArray")
- .execute()) {
- final String content = curlResponse.getContentAsString();
- final String[] lines = content.split("\n");
- assertTrue(!lines[1].contains("\"x_lon\":"));
- assertTrue(!lines[1].contains("\"x_lat\":"));
- assertTrue(!lines[1].contains("\"iii\":{\"jjj\":\"static test\"}"));
- assertTrue(!lines[1].contains("\"x_alt\":"));
- assertTrue(lines[1].matches("(.+)\"geometry\":\\{\"type\":\"Point\",\"coordinates\":\\[[0-9\\.\\-]+,[0-9\\.\\-]+,[0-9\\.\\-]+\\](.+)"));
- }
-
- // normal call with "type_field" and "coord_field"
- try (CurlResponse curlResponse = EcrCurl.get(node, "/dataset1/_data")
- .header("Content-Type", "application/json")
- .param("format", "geojson")
- .param("geometry.type_field", "x_type")
- .param("geometry.coord_field", "x_coord")
- .execute()) {
- final String content = curlResponse.getContentAsString();
- final String[] lines = content.split("\n");
- assertTrue(!lines[1].contains("\"x_coord\":["));
- assertTrue(!lines[1].contains("\"x_type\":"));
- assertTrue(lines[1].matches("(.+)\"coordinates\":\\[[0-9,\\.\\-\\[\\]]+\\](.+)"));
- }
-
- // Bad "geometry.coord_field" value
- try (CurlResponse curlResponse = EcrCurl.get(node, "/dataset1/_data")
- .header("Content-Type", "application/json")
- .param("format", "geojson")
- .param("geometry.type_field", "x_type")
- .param("geometry.coord_field", "x_coords")
- .execute()) {
- final String content = curlResponse.getContentAsString();
- final String[] lines = content.split("\n");
- assertTrue(lines[1].contains("\"coordinates\":[]"));
- assertTrue(lines[1].contains("\"x_coord\":["));
- }
-
- // Look for "geometry.type_field" value in array at index 1
- try (CurlResponse curlResponse = EcrCurl.get(node, "/dataset1/_data")
- .header("Content-Type", "application/json")
- .param("format", "geojson")
- .param("geometry.type_field", "x_typeArray[1]")
- .param("geometry.coord_field", "x_coord")
- .execute()) {
- final String content = curlResponse.getContentAsString();
- final String[] lines = content.split("\n");
- assertTrue(lines[1].contains("\"x_typeArray\":[\"badtype\",\"badtype\"]"));
- }
- }
-
- @Test
- public void dumpGeoJsonInFile() throws IOException {
- paramsGeoJson.put("file", geojsonTempFile.getAbsolutePath());
-
- try (CurlResponse curlResponse = createRequest(node, pathgeo, paramsGeoJson).execute()) {
- assertAcknowledged(curlResponse, geojsonTempFile);
- final List lines = Files.readAllLines(geojsonTempFile.toPath(), Charsets.UTF_8);
- assertEquals(docNumber + 2, lines.size());
- assertTrue(lines.get(0).equals("{\"type\": \"FeatureCollection\", \"features\": ["));
- assertTrue(lines.get(1).startsWith("{\"type\":\"Feature\",\"geometry\":{\"type\":\""));
- assertTrue(lines.get(docNumber).startsWith("{\"type\":\"Feature\",\"geometry\":{\"type\":\""));
- assertTrue(lines.get(docNumber + 1).equals("]}"));
- }
- }
-
@Test
public void dumpSizeLimit() throws IOException {
@@ -684,18 +558,15 @@ public void dumpSizeLimit() throws IOException {
private static void indexing() {
final String index0 = "dataset0";
final String type0 = "_doc";
- final String index1 = "dataset1";
- final String type1 = "_doc";
// create an index
runner.createIndex(index0, (Settings) null);
- runner.createIndex(index1, (Settings) null);
- if (!runner.indexExists(index0) || !runner.indexExists(index1)) {
+ if (!runner.indexExists(index0)) {
Assert.fail();
}
- // create documents for index0
+ // create documents
for (int i = 1; i <= docNumber; i++) {
final IndexResponse indexResponse0 = runner.insert(index0, type0, String.valueOf(i),
"{" +
@@ -706,47 +577,11 @@ private static void indexing() {
"}");
assertEquals(DocWriteResponse.Result.CREATED, indexResponse0.getResult());
}
- // create documents for index1
- final String[] geotypeList = { "Point", "LineString", "Polygon" };
- for (int i = 1; i <= docNumber; i++) {
- String geotype = geotypeList[new Random().nextInt(geotypeList.length)];
- String geocoord = "";
- switch (geotype) {
- case "Point":
- geocoord= "[102.0, 0.5]";
- break;
- case "LineString":
- geocoord= "[[102.0, 0.0], [103.0, 1.0], [104.0, 0.0], [105.0, 1.0]]";
- break;
- case "Polygon":
- geocoord= "[[[100.0, 0.0], [101.0, 0.0], [101.0, 1.0],[100.0, 1.0], [100.0, 0.0]]]";
- break;
- }
-
- final IndexResponse indexResponse1 = runner.insert(index1, type1, String.valueOf(i),
- "{" +
- "\"aaa\":\"test " + i + "\"," +
- "\"bbb\":" + i + "," +
- "\"ccc\":\"2012-01-01:00:00.000Z\"," +
- "\"eee\":{\"fff\":\"TEST " + i + "\", \"ggg\":" + i + ", \"hhh\":\"2013-01-01:00:00.000Z\"}," +
- "\"x_type\":\"" + geotype + "\"," +
- "\"x_typeArray\": [\"badtype\",\"" + geotype + "\",\"badtype\"]," +
- "\"x_coord\": " + geocoord + "," +
- "\"x_lon\": 1" + i + ".0," +
- "\"x_lat\": " + (i/2) + ".0," +
- "\"x_alt\": " + (i/2) + ".0," +
- "\"iii\":{\"x_altSub\": "+ (i*3) + "}" +
- "}");
- assertEquals(DocWriteResponse.Result.CREATED, indexResponse1.getResult());
- }
- // refresh elastic cluster
runner.refresh();
// search documents to verify
- SearchResponse searchResponse0 = runner.search(index0, type0, null, null, 0, 10);
- SearchResponse searchResponse1 = runner.search(index1, type1, null, null, 0, 10);
- assertEquals(docNumber, searchResponse0.getHits().getTotalHits().value);
- assertEquals(docNumber, searchResponse1.getHits().getTotalHits().value);
+ SearchResponse searchResponse = runner.search(index0, type0, null, null, 0, 10);
+ assertEquals(docNumber, searchResponse.getHits().getTotalHits().value);
}
private static File createTempFile(String prefix, String suffix) {