Interesting. You're using a different api than I am to create the
index mapping. I'll need to try that. Thanks for the code resource,
very neat and understandable.
- Craig
On Thu, May 24, 2012 at 3:47 PM, David Pilato david@pilato.fr wrote:
Hi Craig,
Not sure it will fit to your needs but I wrote something here that create an
index using settings.
https://github.com/dadoonet/spring-elasticsearch/blob/master/src/main/java/f
r/pilato/spring/elasticsearch/ElasticsearchAbstractClientFactoryBean.java#L6
69Also, I define new mappings as follow :
https://github.com/dadoonet/spring-elasticsearch/blob/master/src/main/java/f
r/pilato/spring/elasticsearch/ElasticsearchAbstractClientFactoryBean.java#L6
09PutMappingResponse response =client.admin().indices()
.preparePutMapping(index)
.setType(type)
.setSource(source)
.execute().actionGet();Source is a String containing:
{
"tweet" : {
"properties" : {
"message" : {"type" : "string", "store" : "yes"}
}
}
}
(see
https://github.com/dadoonet/spring-elasticsearch/blob/master/src/test/resour
ces/es1/twitter/tweet.json )Hope this could help you to solve your issue.
David.-----Message d'origine-----
De : elasticsearch@googlegroups.com
[mailto:elasticsearch@googlegroups.com] De la part de Craig Brown
Envoyé : jeudi 24 mai 2012 23:36
À : elasticsearch
Objet : Need mapping help with unit test in java api.I have a json mapping file that I user for unit testing that is based
on the one I use with CURL. It looks like the java api only accepts the
"mapping: {}" section that starts with the type like this:client.admin() .indices() .create(createIndexRequest("myIndex") .mapping("records", "records:{}") ) .actionGet();I want to add an edgeNGram tokenizer to a field and it looks like it
needs to be specified as follows:
{
"settings" : {
"analysis": {
"analyzer": {
"containsText" : {
"tokenizer": "whitespace",
"filter": ["lowercase", "autocomplete"]
}
},
"filter": {
"autocomplete": {"type": "edgeNGram", "min_gram": "1",
"max_gram": "50", "side": "front"}
}
}
},
"mappings" : {
"records" : {
"properties" : {
"name":{"type":"string", "analyzer":"containsText"}
}
}
}
}This seems to work from the REST api, but the java mapping api gives
the following exception.
org.elasticsearch.index.mapper.MapperParsingException: mapping
[records]
at org.elasticsearch.cluster.metadata.MetaDataCreateIndexService
$1.execute(MetaDataCreateIndexService.java:244)
at org.elasticsearch.cluster.service.InternalClusterService
$2.run(InternalClusterService.java:211)
at java.util.concurrent.ThreadPoolExecutor
$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor
$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
Caused by: org.elasticsearch.index.mapper.MapperParsingException:
Mapping must have thetypeas the root object
at
org.elasticsearch.index.mapper.DocumentMapperParser.extractMapping(Docu
mentMapperParser.java:
231)
at
org.elasticsearch.index.mapper.DocumentMapperParser.parse(DocumentMappe
rParser.java:
141)
at
org.elasticsearch.index.mapper.MapperService.parse(MapperService.java:
269)
at
org.elasticsearch.index.mapper.MapperService.add(MapperService.java:
172)
at org.elasticsearch.cluster.metadata.MetaDataCreateIndexService
$1.execute(MetaDataCreateIndexService.java:241)How can I set this mapping up using the java api so that I can perform
some unit testing with ngrams to make sure they are working correctly?Thanks!
- Craig
--
…
CRAIG BROWN
chief architect
youwho, Inc.
T: 801.855. 0921
M: 801.913. 0939