Problem in ElasticSearch Analyzer using Java API

Hello,

following is my java code to create index using the mappings and settings.
however its creating the index with given name but when we run following
command

curl -XGET 'http://localhost:9200/test/test/_mapping'

we get : {"error":"TypeMissingException[[test] type[test]
missing]","status":404}

and also curl -XGET 'http://localhost:9200/test/_mapping'

gives {"test":{}}

which is neither showing the mappings nor analyzer.

public void createIndex(String indexName, String type) throws IOException {
    client.admin().indices().prepareCreate(indexName)

.setSettings(ImmutableSettings.settingsBuilder().loadFromSource(jsonBuilder()
.startObject()
.startObject("mappings")
.startObject(type)
.startObject("properties")
.startObject("firstName")
.field("type", "string")
.field("search_analyzer",
"name_analyzer")
.field("index_analyzer",
"name_analyzer")
.endObject()
.startObject("email")
.field("type", "string")
.field("search_analyzer",
"email_analyzer")
.field("index_analyzer",
"email_analyzer")
.endObject()
.endObject()
.endObject()
.endObject()
.startObject("settings")
.startObject("analysis")
.startObject("analyzer")
.startObject("name_analyzer")
.field("filter",new
String[]{"standard","lowercase","asciifolding"})
.field("type","custom")
.field("tokenizer","standard")
.endObject()
.startObject("email_analyzer")
.field("type","custom")

.field("tokenizer","uax_url_email")
.endObject()
.endObject()
.endObject()
.endObject()
.endObject().toString()))

            .execute().actionGet();
}

problem is that it is not showing the mappings with properties and settings
for analyzer.

please suggest

Thanks

--

UP

On Monday, 26 November 2012 15:27:42 UTC, mohsin husen wrote:

Hello,

following is my java code to create index using the mappings and settings.
however its creating the index with given name but when we run following
command

curl -XGET 'http://localhost:9200/test/test/_mapping'

we get : {"error":"TypeMissingException[[test] type[test]
missing]","status":404}

and also curl -XGET 'http://localhost:9200/test/_mapping'

gives {"test":{}}

which is neither showing the mappings nor analyzer.

public void createIndex(String indexName, String type) throws IOException {
    client.admin().indices().prepareCreate(indexName)

.setSettings(ImmutableSettings.settingsBuilder().loadFromSource(jsonBuilder()
.startObject()
.startObject("mappings")
.startObject(type)
.startObject("properties")
.startObject("firstName")
.field("type", "string")
.field("search_analyzer",
"name_analyzer")
.field("index_analyzer",
"name_analyzer")
.endObject()
.startObject("email")
.field("type", "string")
.field("search_analyzer",
"email_analyzer")
.field("index_analyzer",
"email_analyzer")
.endObject()
.endObject()
.endObject()
.endObject()
.startObject("settings")
.startObject("analysis")
.startObject("analyzer")
.startObject("name_analyzer")
.field("filter",new
String[]{"standard","lowercase","asciifolding"})
.field("type","custom")
.field("tokenizer","standard")
.endObject()
.startObject("email_analyzer")
.field("type","custom")

.field("tokenizer","uax_url_email")
.endObject()
.endObject()
.endObject()
.endObject()
.endObject().toString()))

            .execute().actionGet();
}

problem is that it is not showing the mappings with properties and
settings for analyzer.

please suggest

Thanks

--

In your code, you set mapping + settings at the settings level:

client.admin().indices().prepareCreate(indexName).setSettings(...your JSON
with mapping and settings...)

That's why your settings and mappings are not parsed by elasticsearch.

You can try something like:

client.admin().indices().prepareCreate(indexName)

.setSettings("... your JSON settings..")

.addMapping(type, "... your mapping...")

-- Tanguy

Le lundi 26 novembre 2012 16:27:42 UTC+1, mohsin husen a écrit :

Hello,

following is my java code to create index using the mappings and settings.
however its creating the index with given name but when we run following
command

curl -XGET 'http://localhost:9200/test/test/_mapping'

we get : {"error":"TypeMissingException[[test] type[test]
missing]","status":404}

and also curl -XGET 'http://localhost:9200/test/_mapping'

gives {"test":{}}

which is neither showing the mappings nor analyzer.

public void createIndex(String indexName, String type) throws IOException {
    client.admin().indices().prepareCreate(indexName)

.setSettings(ImmutableSettings.settingsBuilder().loadFromSource(jsonBuilder()
.startObject()
.startObject("mappings")
.startObject(type)
.startObject("properties")
.startObject("firstName")
.field("type", "string")
.field("search_analyzer",
"name_analyzer")
.field("index_analyzer",
"name_analyzer")
.endObject()
.startObject("email")
.field("type", "string")
.field("search_analyzer",
"email_analyzer")
.field("index_analyzer",
"email_analyzer")
.endObject()
.endObject()
.endObject()
.endObject()
.startObject("settings")
.startObject("analysis")
.startObject("analyzer")
.startObject("name_analyzer")
.field("filter",new
String[]{"standard","lowercase","asciifolding"})
.field("type","custom")
.field("tokenizer","standard")
.endObject()
.startObject("email_analyzer")
.field("type","custom")

.field("tokenizer","uax_url_email")
.endObject()
.endObject()
.endObject()
.endObject()
.endObject().toString()))

            .execute().actionGet();
}

problem is that it is not showing the mappings with properties and
settings for analyzer.

please suggest

Thanks

--

Thanks Tanguy !
yea i am trying now as per your suggestion.
i was wondering like can we load mappings as well from json file like we
are doing it with loadfromfile(setings) ?
Thanks

Mohsin

On Monday, 26 November 2012 15:27:42 UTC, mohsin husen wrote:

Hello,

following is my java code to create index using the mappings and settings.
however its creating the index with given name but when we run following
command

curl -XGET 'http://localhost:9200/test/test/_mapping'

we get : {"error":"TypeMissingException[[test] type[test]
missing]","status":404}

and also curl -XGET 'http://localhost:9200/test/_mapping'

gives {"test":{}}

which is neither showing the mappings nor analyzer.

public void createIndex(String indexName, String type) throws IOException {
    client.admin().indices().prepareCreate(indexName)

.setSettings(ImmutableSettings.settingsBuilder().loadFromSource(jsonBuilder()
.startObject()
.startObject("mappings")
.startObject(type)
.startObject("properties")
.startObject("firstName")
.field("type", "string")
.field("search_analyzer",
"name_analyzer")
.field("index_analyzer",
"name_analyzer")
.endObject()
.startObject("email")
.field("type", "string")
.field("search_analyzer",
"email_analyzer")
.field("index_analyzer",
"email_analyzer")
.endObject()
.endObject()
.endObject()
.endObject()
.startObject("settings")
.startObject("analysis")
.startObject("analyzer")
.startObject("name_analyzer")
.field("filter",new
String[]{"standard","lowercase","asciifolding"})
.field("type","custom")
.field("tokenizer","standard")
.endObject()
.startObject("email_analyzer")
.field("type","custom")

.field("tokenizer","uax_url_email")
.endObject()
.endObject()
.endObject()
.endObject()
.endObject().toString()))

            .execute().actionGet();
}

problem is that it is not showing the mappings with properties and
settings for analyzer.

please suggest

Thanks

--