smhdiu
(smhdiu)
November 26, 2012, 3:27pm
1
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
--
smhdiu
(smhdiu)
November 27, 2012, 11:13am
2
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
--
Tanguy1
(Tanguy)
November 27, 2012, 11:20am
3
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
--
smhdiu
(smhdiu)
November 27, 2012, 2:33pm
4
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
--