3

I have following mapping in elastic search. I am able to PUT documents using Sense plugin but unable to do so using XContentBuilder to set the geo_shape field value. I am getting following error:

error:

[106]: index [streets], type [street], id [{dc872755-f307-4c5e-93f6-bba9c95791c7}], message [MapperParsingException[failed to parse [shape]]; nested: ElasticsearchParseException[shape must be an object consisting of type and coordinates];]

mapping:

PUT /streets
    {
       "mappings": {
          "street": {
             "properties": {
                "id": {
                   "type": "string"
                },
                "shape": {
                   "type": "geo_shape",
                   "tree": "quadtree"
                }
             }
          }
       }
    }

code:

val bulkRequest:BulkRequestBuilder = esClient.prepareBulk()
//inloop
    xb = jsonBuilder().startObject()      
    xb.field("id", guid)
    xb.field("shape", jsonString) // removing this line creates the index OK but without the geo_shape
    xb.endObject()
    bulkRequest.add(esClient.prepareIndex("streets", "street", guid).setSource(xb))
//end loop


    val bulkResponse:BulkResponse = bulkRequest.execute().actionGet()

    if(bulkResponse.hasFailures){
          println(bulkResponse.buildFailureMessage())
    }

jsonString:

{
    "id": "{98b8fd8d-074c-4349-a83b-6e892bf2d0ef}",
    "shape": {
        "type": "LineString",
        "coordinates": [
            [-70.81866815832467, 43.12187109162505],
            [-70.83054813653018, 43.15917412985851],
            [-70.81320737213957, 43.23522269547419],
            [-70.90108590067649, 43.28102004268419]
        ],
        "crs": {
            "type": "name",
            "properties": {
                "name": "EPSG:4326"
            }
        }
    }
}

Appreciate any feedback?

Thanks

Vms
  • 199
  • 2
  • 11

1 Answers1

0

It might be a bit late for you, but this could help someone facing a similar issue even nowadays.

Following your index mapping for the document streets, we have these properties: id and shape.

In your error message, it's described that:

shape must be an object consisting of type and coordinates

So for your concrete case, the crs array is just not accepted (don't know exactly why you can't add extra parameters).

This is an example for how to add a document into the streets index using CURL:

curl -X POST "localhost:9200/streets/_doc?pretty" -H 'Content-Type: application/json' -d '
{
"id": 123,
"shape": {
    "type": "Polygon",
    "coordinates": [
        [
            [
                32.85444259643555,
                39.928694653732364
            ],
            [
                32.847232818603516,
                39.9257985682691
            ],
            [
                32.837791442871094,
                39.91947941109337
            ],
            [
                32.837276458740234,
                39.91579296675271
            ],
            [
                32.85392761230469,
                39.913423004886894
            ],
            [
                32.86937713623047,
                39.91329133793421
            ],
            [
                32.88036346435547,
                39.91539797880347
            ],
            [
                32.85444259643555,
                39.928694653732364
            ]
        ]
    ]
}
}'

If you need to add a LineString, instead of a Polygon, just change the 'type' attribute from the 'shape'.

I hope this helps people having to add documents with shapes into an ElasticSearch database.

xarlymg89
  • 2,552
  • 2
  • 27
  • 41