I have two float fields that represent a latitude and longitude. I want to perform an _update_by_query and add a new geo_shape field to each document using the values from the lat/lon fields.
The ctx._source is a Map. It will not auto create fields. So you would either have to create sub maps (containing area and geo_shape keys), or just create a single field from the root (the dots will automatically be handled when indexing). Eg:
You should also aware that coordinates for a geo shape must be in an array, but what you have in your example is a geo json array, so you need to double it. Also not that this will never work, you cannot set mappings inside a document:
ctx._source.area.geo_shape['type']="point";
Finally, why are you using a geo_shape for a single point? You should use a geo_point.
I am trying to use the geo_shape query to determine if a point is located within a preindexed set of geo_shapes. geo_point doesn't work in that scenario.
FWIW, if the document already has a geo_shape field defined, I can use Painless to update the coordinates and the type. The following code works fine:
What I really want is for my script to add a new geo_shape field to the doc, but if I run the _update_by_query above on the following document, I get a null_pointer_exception:
PUT test/doc/2
{
"lon" : -87.942655,
"lat" : 42.034714
}
What is the syntax for adding a new geo_shape field to a document in Painless?
FWIW: I could not figure out the Painless syntax, so I just moved the work back to Logstash and reindexed. Here is what the Logstash config looked like:
"cause": {
"type": "mapper_parsing_exception",
"reason": "Could not dynamically add mapping for field [area.geo_shape.coordinates]. Existing mapping for [area.geo_shape] must be of type object but found [geo_shape]."
}
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.