Elasticsearch on nested datatype : MapperParsingException


(Saurab Dahal) #1

this is my mapping

   {
  "mappings": {
    "data_test": {
      "properties": {
        "type": {
          "type": "keyword"
        },
        "geometry": {
          "type": "geo_point"
        },
        "proper": {
          "type":"nested",
          "properties": {
            "gid": {
              "type": "keyword"
            },
            "objectid": {
              "type": "keyword"
            },
            "nombre_del": {
              "type": "keyword"
            },
            "tipo_de_si": {
              "type": "double"
            },
            "codigo_de_": {
              "type": "double"
            }
          }
        }
      }
    }
  }
}

as per this link anyfield with nested key:value pair will be treated as object and we need to provide an object to index the document. I have a data that looks like this (a sample)

"type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "geometry": {
        "type": "Point",
        "coordinates": [
          -74.0743290075,
          4.64168349373
        ]
      },
      "properties": {
        "gid": 14,
        "objectid": "986",
        "nombre_del": "Banco Popular",
        "tipo_de_si": "15",
        "codigo_de_": "13"
      }
    }

]

and my java code to index this data

for (Object s : jar){
        JSONObject proper = new JSONObject(new JSONObject(s.toString()).get("properties").toString());
        System.out.println(proper);   /// this prints

{"gid":353,"nombre_del":"Banco Colpatria Red Multibanca","tipo_de_si":"15","codigo_de_":"15","objectid":"10835"}

bulkRequest.add(client.prepareIndex("geo_data_test", "data_test")
                .setSource(jsonBuilder()
                        .startObject()
                        .field("type",new JSONObject(s.toString()).get("type"))
                        .field("geometry",new JSONObject(new JSONObject(s.toString()).get("geometry").toString()).get("coordinates"))
                        .field("proper",proper)
                        .endObject()
                )
        );
    }

    BulkResponse r = bulkRequest.get();
    Consumer<BulkItemResponse> c = (s) -> System.out.println(s.getFailureMessage());
    r.forEach(c);
    client.close();

if I run this I get
MapperParsingException[object mapping for [proper] tried to parse field [proper] as object, but found a concrete value]
but the proper variable is an object, so should it not be indexed ? or I am understanding wrong ?


(system) #2

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