How to put Geo_type mapping with JsonObject

(sijia) #1

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!

(Ignacio Vera) #2

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.

(sijia) #3

Failed to execute phase [query], all shards failed; shardFailures {[eQoH4XkNTUutOsYZZsTVcA][landsat8][0]: RemoteTransportException[[eQoH4Xk][][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" : [
I don't know how to put geo_type use JavaCode.
There is two problems:

  1. how to put mapping geo_type from a JsonObject?

     Location location = new Location;
     PolygonBuilder polygonBuilder = new PolygonBuilder(coordinate);
     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?
how can I put a JsonObject to put it?
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~

(David Pilato) #4

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.

(sijia) #5

Can I use JavaCode to define a mapping?
Or just can define a mapping use kibana?

(David Pilato) #6

Both are possible.

(sijia) #7

If I define a mapping is not text, Can I use JsonObject to put to ES?
Thank you for your answer.

(sijia) #8

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.

(David Pilato) #9

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:


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.

(sijia) #10

`class MTL{
private String polygon;

    private String polygon;

    private String id;
MTL mtl = new MTL();
PolygonBuilder polygonBuilder = new PolygonBuilder(coordinate);
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.

(David Pilato) #11

I can't reproduce anything with that. You should share a full demo project on Github.

(system) closed #12

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.