You should absolutely use the Java API and not use straight JSON if you are using the Java client. The Java API is not well documented, but the best way to see how it is utilized is by examining the test classes or the corresponding RestAction class. In this case, RestPutMappingAction won't help you since it uses JSON, but there are the test classes. Take a look at
https://github.com/elasticsearch/elasticsearch/tree/master/src/test/java/org/elasticsearch/indices/mapping https://github.com/elasticsearch/elasticsearch/blob/master/src/test/java/org/elasticsearch/index/mapper/source/DefaultSourceMappingTests.java I do not use the Java API for mappings since I prefer to use file-based (dynamic templates) solutions since I can store the files in version control, but the API is somewhere there. -- Ivan On Fri, Mar 28, 2014 at 2:20 PM, Jacob Stultz <[email protected]> wrote: > I'm wondering how feasible it is to use some of the Java classes defined > by Elasticsearch on the client side, rather than building up JSON strings > or XContentBuilder instances manually. Specifically, I'm wondering about > creating mappings. It would be really nice if I could create a > DocumentMapper instance (which implements ToXContent) to define a mapping, > and then use that to create an XContentBuilder to pass to setSource on > PutMappingRequestBuilder. > > This would be great, since it would rely on existing types to ensure that > valid mappings are created, rather than leaving open the possibility of > incorrectly constructing JSON (either via typos or incorrect field names, > or just incorrect structure). > > However, I'm having trouble figuring out whether this is possible or > intended; it seems to create a DocumentMapper instance, I'd need a > DocumentMapper.Builder instance, which requires a DocumentMapperParser > instance to build the DocumentMapper, and the DocumentMapperParser instance > in turn requires a number of other objects not readily available. > > Am I basically stuck with writing my own code to generate these JSON > structures? If so, it'd be really nice in the future if the Java API would > leverage the fact that much of the code is already used on the server side, > and make those classes easily available for clients to leverage static > typing to help ensure correctness. > > Thanks. > > -- > 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 [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/elasticsearch/8cbf0f15-a5d2-4dda-9759-ede3505ca08e%40googlegroups.com<https://groups.google.com/d/msgid/elasticsearch/8cbf0f15-a5d2-4dda-9759-ede3505ca08e%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- 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 [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQAp32JA6MdG9KYicGLvaUXSb9VwH3ed%2Bf_sAqxfzAR-aQ%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
