Hi all ,does everyone knows how to use :
IndexResponse createData(Client client, String jsonObject,
String index, String type, String id);
to put Geo_type and other mappings?
I used Map resolve this issue,but I also don't know how to save PolygonBuilder to a Object and then Object to json, and then put json to Elasticsearch, if u see this issue, pls tell how to do it.Thank you very much!
I don't really understand what you are trying to do, could you please try to expand your explanation, maybe adding some pseudo-code with what you are trying to.
Failed to execute phase [query], all shards failed; shardFailures {[eQoH4XkNTUutOsYZZsTVcA][landsat8][0]: RemoteTransportException[[eQoH4Xk][127.0.0.1:9300][indices:data/read/search[phase/query]]]; nested: QueryShardException[Field [polygon] is not of type [geo_shape] but of type [text]];
kibana shows:
"polygon" : """
{
"type" : "polygon",
"orientation" : "right",
"coordinates" : [
[
[
116.45673,
39.96037
],
[
119.15366,
39.94163
],
[
119.0907,
37.82628
],
[
116.47263,
37.84366
],
[
116.45673,
39.96037
]
]
]
}
""".
I don't know how to put geo_type use JavaCode.
There is two problems:
-
how to put mapping geo_type from a JsonObject?
like:Location location = new Location; PolygonBuilder polygonBuilder = new PolygonBuilder(coordinate); polygon.setPolygon(polygonBuilder.toString()); String json = JSON.toJSONString(location); client.prepareIndex(index, type,id) .setSource(json, XContentType.JSON).get() All the properties in location is String, and I put json to ES, polygon type is text. I need type geo_shape to do some intersection.
I can use mapping and update to solve this, but I think there is another way.
2. how to put a geo_type polygon from a JsonObject?
If
"polygon"{
"type":"geo_type"
}
how can I put a JsonObject to put it?
example:
class Location{
private String polygon;
}
or I need to do like this :
class Location{
private PolygonBuilder polygon;
}
but if like this,I can't do polygon to json.
pls tell me how to do this. thank you very much!
And thank for your patient~
You probably did not define a mapping when you indexed your first document.
So the current mapping contains a polygon
field with a text
type.
You need to fix the mapping.
Can I use JavaCode to define a mapping?
Or just can define a mapping use kibana?
Both are possible.
https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/java-rest-high-create-index.html
If I define a mapping is not text, Can I use JsonObject to put to ES?
Thank you for your answer.
If I have a json like this: {"extractType":"dsafa","filePath":"123","location":"154"}
,I used client.prepareIndex(index, type,id) .setSource(json, XContentType.JSON).get()
it just can define the type text.If I fix the mapping, I can't put json by this way.
I don't understand the full picture TBH. Could you share a full example of what you are doing and what the recent problem is?
Don't forget to format your code, logs or configuration files using </>
icon as explained in this guide and not the citation button. It will make your post more readable.
Or use markdown style like:
```
CODE
```
This is the icon to use if you are not using markdown format:
There's a live preview panel for exactly this reasons.
Lots of people read these forums, and many of them will simply skip over a post that is difficult to read, because it's just too large an investment of their time to try and follow a wall of badly formatted text.
If your goal is to get an answer to your questions, it's in your interest to make it as easy to read and understand as possible.
JavaCode:
`class MTL{
private String polygon;
private String polygon;
private String id;
}
MTL mtl = new MTL();
PolygonBuilder polygonBuilder = new PolygonBuilder(coordinate);
mtl.setPolygon(polygonBuilder.toString);
String str = JSON.toJSONString(mtl);
client.prepareIndex(index, type,id)
.setSource(str, XContentType.JSON).get();
`
I get the mapping is String,not geo_shape.If I fixed the mapping to geo_shape,I can't put it to ES.
I can't reproduce anything with that. You should share a full demo project on Github.
This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.