Adding mapping and settings using Java API

Hi guys,

I'm using ES 0.90.02. I followed kimchy's advice on this similar post (
http://elasticsearch-users.115913.n3.nabble.com/updating-settings-and-mapping-with-java-API-td3707085.html)
but the code I've written doesn't seem to work when the mapping file
includes a geospatially coded attribute. Here's the code that I have
written to create an index and add the necessary mapping and settings to
the index.

URL mappingUrl = this.getClass().getResource("/test-mapping.json");
String mappingStr = FileUtils
    .readFileToString(new File(mappingUrl.toURI()));

URL settingsUrl = this.getClass().getResource("/test-settings.json");
String settingsStr = FileUtils.readFileToString(new File(settingsUrl
    .toURI()));

client.admin().indices().prepareCreate("inmemory-data-registry")
    .setSettings(settingsStr)
    .addMapping("dataset", mappingStr).execute()
    .actionGet();

And here's the test-mapping.json file:

{
"properties" : {
"dataSourceURI": {
"type": "string",
"index": "not_analyzed"
},
"location":{
"type":"geo_shape",
"store":"yes",
"tree":"quadtree",
"precision":"1m"
},
"title" : {
"fields" : {
"metaphone" : {
"type" : "string",
"analyzer" : "name_metaphone"
},
"partial" : {
"search_analyzer" : "full_name",
"index_analyzer" : "partial_name",
"type" : "string"
},
"title" : {
"type" : "string",
"analyzer" : "full_name"
}
},
"type" : "multi_field"
}
}
}

And the test-settings.json file

{
"analysis" : {
"filter" : {
"name_ngrams" : {
"side" : "front",
"max_gram" : 10,
"min_gram" : 1,
"type" : "edgeNGram"
},
"name_metaphone" : {
"replace" : false,
"encoder" : "metaphone",
"type" : "phonetic"
}
},
"analyzer" : {
"full_name" : {
"filter" : [
"standard",
"lowercase",
"asciifolding"
],
"type" : "custom",
"tokenizer" : "standard"
},
"name_metaphone" : {
"filter" : [
"name_metaphone"
],
"type" : "custom",
"tokenizer" : "standard"
},
"partial_name" : {
"filter" : [
"standard",
"lowercase",
"asciifolding",
"name_ngrams"
],
"type" : "custom",
"tokenizer" : "standard"
}
}
}
}

The problem I have is when I run a "within" bounds query on the dataset, I
get an exception telling me that the response couldn't be deserialized. And
if I run a curl query from the terminal, it will give me this response...

$ curl -XGET
'http://localhost:9200/inmemory-data-registry/dataset/_search?pretty=true'
-d '{

"query": {  
        "geo_shape" : {
            "location" : {
              "shape":{
                 "type":"envelope",
                 "coordinates" : [[95,-8],[161,-45]]
              }
            }
        }
}

}
'
{
"error" : "SearchPhaseExecutionException[Failed to execute phase [query],
total failure; shardFailures
{[tSWUhOGTQdy9pmRZs0Mebw][inmemory-data-registry][4]:
SearchParseException[[inmemory-data-registry][4]: from[-1],size[-1]: Parse
Failure [Failed to parse source [{\n "query": { \n
"geo_shape" : {\n "location" : {\n
"shape":{\n "type":"envelope",\n
"coordinates" : [[95,-8],[161,-45]]\n }\n
}\n }\n }\n}\n]]]; nested:
QueryParsingException[[inmemory-data-registry] Failed to find geo_shape
field [location]]; }{[tSWUhOGTQdy9pmRZs0Mebw][inmemory-data-registry][2]:
SearchParseException[[inmemory-data-registry][2]: from[-1],size[-1]: Parse
Failure [Failed to parse source [{\n "query": { \n
"geo_shape" : {\n "location" : {\n
"shape":{\n "type":"envelope",\n
"coordinates" : [[95,-8],[161,-45]]\n }\n
}\n }\n }\n}\n]]]; nested:
QueryParsingException[[inmemory-data-registry] Failed to find geo_shape
field [location]]; }{[tSWUhOGTQdy9pmRZs0Mebw][inmemory-data-registry][0]:
SearchParseException[[inmemory-data-registry][0]: from[-1],size[-1]: Parse
Failure [Failed to parse source [{\n "query": { \n
"geo_shape" : {\n "location" : {\n
"shape":{\n "type":"envelope",\n
"coordinates" : [[95,-8],[161,-45]]\n }\n
}\n }\n }\n}\n]]]; nested:
QueryParsingException[[inmemory-data-registry] Failed to find geo_shape
field [location]]; }{[tSWUhOGTQdy9pmRZs0Mebw][inmemory-data-registry][1]:
SearchParseException[[inmemory-data-registry][1]: from[-1],size[-1]: Parse
Failure [Failed to parse source [{\n "query": { \n
"geo_shape" : {\n "location" : {\n
"shape":{\n "type":"envelope",\n
"coordinates" : [[95,-8],[161,-45]]\n }\n
}\n }\n }\n}\n]]]; nested:
QueryParsingException[[inmemory-data-registry] Failed to find geo_shape
field [location]]; }]",
"status" : 500

The problem I'm seeing is that if I run the curl command below, the mapping
process works fine and gives me back the data I've asked for

curl -X PUT -H "Content-Type: application/json" --data @mapping.json
http://127.0.0.1:9200/inmemory-data-registry

with mapping.json:

{
"mappings" : {
"dataset" : {
"properties" : {
"dataSourceURI": {
"type": "string",
"index": "not_analyzed"
},
"location":{
"type":"geo_shape",
"store":"yes",
"tree":"quadtree",
"precision":"1m"
},
"title" : {
"fields" : {
"metaphone" : {
"type" : "string",
"analyzer" : "name_metaphone"
},
"partial" : {
"search_analyzer" : "full_name",
"index_analyzer" : "partial_name",
"type" : "string"
},
"title" : {
"type" : "string",
"analyzer" : "full_name"
}
},
"type" : "multi_field"
}
}
}
},
"settings": {
"analysis" : {
"filter" : {
"name_ngrams" : {
"side" : "front",
"max_gram" : 10,
"min_gram" : 1,
"type" : "edgeNGram"
},
"name_metaphone" : {
"replace" : false,
"encoder" : "metaphone",
"type" : "phonetic"
}
},
"analyzer" : {
"full_name" : {
"filter" : [
"standard",
"lowercase",
"asciifolding"
],
"type" : "custom",
"tokenizer" : "standard"
},
"name_metaphone" : {
"filter" : [
"name_metaphone"
],
"type" : "custom",
"tokenizer" : "standard"
},
"partial_name" : {
"filter" : [
"standard",
"lowercase",
"asciifolding",
"name_ngrams"
],
"type" : "custom",
"tokenizer" : "standard"
}
}
}
}
}

And the query response

$ curl -XGET
'http://localhost:9200/inmemory-data-registry/dataset/_search?pretty=true'
-d '{
"query": {
"geo_shape" : {
"location" : {
"shape":{
"type":"envelope",
"coordinates" : [[95,-8],[161,-45]]
}
}
}
}
}
'
{
"took" : 5,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 1,
"max_score" : 1.0,
"hits" : [ {
"_index" : "inmemory-data-registry",
"_type" : "dataset",
"_id" : "dataset-neworg-aurin:testdata23",
"_score" : 1.0, "_source" :
{"abstract":"finance","referenceSystemIdentifier":"EPSG:4283","location":{"type":"envelope","coordinates":[[96.8,-9.1],[159.1,-43.7]]},"geomField":"the_geom","keyword":"lrt,
mrt,
train","organisation":"neworg","dataSourceURI":"datasource-aurinorg-richyrichg","type":"dataset","_rev":"1-16e01c9a819a71b3e5eec9f2ed708320","title":"title","_id":"dataset-neworg-aurin:testdata23","geoLevel":"sa5","name":"aurin:testdata23","key":"mykey","availability":true}
} ]
}
}

Can you guys tell me if I'm doing anything wrong?

Thanks,
Gerson

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Hi guys,

I fixed the issue I reported below by editing the test-mapping.json file
and enclosing the "properties" object inside my 'type' object

{
"dataset": {
"properties" : {}
}
}

Cheers

On Thursday, October 17, 2013 4:39:49 PM UTC+11, Gerson Galang wrote:

Hi guys,

I'm using ES 0.90.02. I followed kimchy's advice on this similar post (
http://elasticsearch-users.115913.n3.nabble.com/updating-settings-and-mapping-with-java-API-td3707085.html)
but the code I've written doesn't seem to work when the mapping file
includes a geospatially coded attribute. Here's the code that I have
written to create an index and add the necessary mapping and settings to
the index.

URL mappingUrl = this.getClass().getResource("/test-mapping.json");
String mappingStr = FileUtils
    .readFileToString(new File(mappingUrl.toURI()));

URL settingsUrl = this.getClass().getResource("/test-settings.json");
String settingsStr = FileUtils.readFileToString(new File(settingsUrl
    .toURI()));

client.admin().indices().prepareCreate("inmemory-data-registry")
    .setSettings(settingsStr)
    .addMapping("dataset", mappingStr).execute()
    .actionGet();

And here's the test-mapping.json file:

{
"properties" : {
"dataSourceURI": {
"type": "string",
"index": "not_analyzed"
},
"location":{
"type":"geo_shape",
"store":"yes",
"tree":"quadtree",
"precision":"1m"
},
"title" : {
"fields" : {
"metaphone" : {
"type" : "string",
"analyzer" : "name_metaphone"
},
"partial" : {
"search_analyzer" : "full_name",
"index_analyzer" : "partial_name",
"type" : "string"
},
"title" : {
"type" : "string",
"analyzer" : "full_name"
}
},
"type" : "multi_field"
}
}
}

And the test-settings.json file

{
"analysis" : {
"filter" : {
"name_ngrams" : {
"side" : "front",
"max_gram" : 10,
"min_gram" : 1,
"type" : "edgeNGram"
},
"name_metaphone" : {
"replace" : false,
"encoder" : "metaphone",
"type" : "phonetic"
}
},
"analyzer" : {
"full_name" : {
"filter" : [
"standard",
"lowercase",
"asciifolding"
],
"type" : "custom",
"tokenizer" : "standard"
},
"name_metaphone" : {
"filter" : [
"name_metaphone"
],
"type" : "custom",
"tokenizer" : "standard"
},
"partial_name" : {
"filter" : [
"standard",
"lowercase",
"asciifolding",
"name_ngrams"
],
"type" : "custom",
"tokenizer" : "standard"
}
}
}
}

The problem I have is when I run a "within" bounds query on the dataset, I
get an exception telling me that the response couldn't be deserialized. And
if I run a curl query from the terminal, it will give me this response...

$ curl -XGET '
http://localhost:9200/inmemory-data-registry/dataset/_search?pretty=true'
-d '{

"query": {  
        "geo_shape" : {
            "location" : {
              "shape":{
                 "type":"envelope",
                 "coordinates" : [[95,-8],[161,-45]]
              }
            }
        }
}

}
'
{
"error" : "SearchPhaseExecutionException[Failed to execute phase
[query], total failure; shardFailures
{[tSWUhOGTQdy9pmRZs0Mebw][inmemory-data-registry][4]:
SearchParseException[[inmemory-data-registry][4]: from[-1],size[-1]: Parse
Failure [Failed to parse source [{\n "query": { \n
"geo_shape" : {\n "location" : {\n
"shape":{\n "type":"envelope",\n
"coordinates" : [[95,-8],[161,-45]]\n }\n
}\n }\n }\n}\n]]]; nested:
QueryParsingException[[inmemory-data-registry] Failed to find geo_shape
field [location]]; }{[tSWUhOGTQdy9pmRZs0Mebw][inmemory-data-registry][2]:
SearchParseException[[inmemory-data-registry][2]: from[-1],size[-1]: Parse
Failure [Failed to parse source [{\n "query": { \n
"geo_shape" : {\n "location" : {\n
"shape":{\n "type":"envelope",\n
"coordinates" : [[95,-8],[161,-45]]\n }\n
}\n }\n }\n}\n]]]; nested:
QueryParsingException[[inmemory-data-registry] Failed to find geo_shape
field [location]]; }{[tSWUhOGTQdy9pmRZs0Mebw][inmemory-data-registry][0]:
SearchParseException[[inmemory-data-registry][0]: from[-1],size[-1]: Parse
Failure [Failed to parse source [{\n "query": { \n
"geo_shape" : {\n "location" : {\n
"shape":{\n "type":"envelope",\n
"coordinates" : [[95,-8],[161,-45]]\n }\n
}\n }\n }\n}\n]]]; nested:
QueryParsingException[[inmemory-data-registry] Failed to find geo_shape
field [location]]; }{[tSWUhOGTQdy9pmRZs0Mebw][inmemory-data-registry][1]:
SearchParseException[[inmemory-data-registry][1]: from[-1],size[-1]: Parse
Failure [Failed to parse source [{\n "query": { \n
"geo_shape" : {\n "location" : {\n
"shape":{\n "type":"envelope",\n
"coordinates" : [[95,-8],[161,-45]]\n }\n
}\n }\n }\n}\n]]]; nested:
QueryParsingException[[inmemory-data-registry] Failed to find geo_shape
field [location]]; }]",
"status" : 500

The problem I'm seeing is that if I run the curl command below, the
mapping process works fine and gives me back the data I've asked for

curl -X PUT -H "Content-Type: application/json" --data @mapping.json
http://127.0.0.1:9200/inmemory-data-registry

with mapping.json:

{
"mappings" : {
"dataset" : {
"properties" : {
"dataSourceURI": {
"type": "string",
"index": "not_analyzed"
},
"location":{
"type":"geo_shape",
"store":"yes",
"tree":"quadtree",
"precision":"1m"
},
"title" : {
"fields" : {
"metaphone" : {
"type" : "string",
"analyzer" : "name_metaphone"
},
"partial" : {
"search_analyzer" : "full_name",
"index_analyzer" : "partial_name",
"type" : "string"
},
"title" : {
"type" : "string",
"analyzer" : "full_name"
}
},
"type" : "multi_field"
}
}
}
},
"settings": {
"analysis" : {
"filter" : {
"name_ngrams" : {
"side" : "front",
"max_gram" : 10,
"min_gram" : 1,
"type" : "edgeNGram"
},
"name_metaphone" : {
"replace" : false,
"encoder" : "metaphone",
"type" : "phonetic"
}
},
"analyzer" : {
"full_name" : {
"filter" : [
"standard",
"lowercase",
"asciifolding"
],
"type" : "custom",
"tokenizer" : "standard"
},
"name_metaphone" : {
"filter" : [
"name_metaphone"
],
"type" : "custom",
"tokenizer" : "standard"
},
"partial_name" : {
"filter" : [
"standard",
"lowercase",
"asciifolding",
"name_ngrams"
],
"type" : "custom",
"tokenizer" : "standard"
}
}
}
}
}

And the query response

$ curl -XGET '
http://localhost:9200/inmemory-data-registry/dataset/_search?pretty=true'
-d '{
"query": {
"geo_shape" : {
"location" : {
"shape":{
"type":"envelope",
"coordinates" : [[95,-8],[161,-45]]
}
}
}
}
}
'
{
"took" : 5,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 1,
"max_score" : 1.0,
"hits" : [ {
"_index" : "inmemory-data-registry",
"_type" : "dataset",
"_id" : "dataset-neworg-aurin:testdata23",
"_score" : 1.0, "_source" :
{"abstract":"finance","referenceSystemIdentifier":"EPSG:4283","location":{"type":"envelope","coordinates":[[96.8,-9.1],[159.1,-43.7]]},"geomField":"the_geom","keyword":"lrt,
mrt,
train","organisation":"neworg","dataSourceURI":"datasource-aurinorg-richyrichg","type":"dataset","_rev":"1-16e01c9a819a71b3e5eec9f2ed708320","title":"title","_id":"dataset-neworg-aurin:testdata23","geoLevel":"sa5","name":"aurin:testdata23","key":"mykey","availability":true}
} ]
}
}

Can you guys tell me if I'm doing anything wrong?

Thanks,
Gerson

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.