The index request is used to index document, you should use put mapping
request.
e,g,
PutMappingResponse response =
client.admin().indices().preparePutMapping(INDEX).setType(INDEX_TYPE).setSource(source).get();
On Wednesday, February 5, 2014 1:27:41 AM UTC+11, Doru Sular wrote:
>
> Hi guys,
>
> I am trying to create an index with the following code:
> XContentBuilder source = XContentFactory.jsonBuilder().startObject()//
> .startObject("settings")
> .field("number_of_shards", 1)
> .endObject()// end settings
> .startObject("mappings")
> .startObject(INDEX_TYPE)//
> .startObject("properties")//
> .startObject("user")
> .field("type", "string") // start user
> .field("store", "yes")
> .field("index", "analyzed")//
> .endObject()// end user
> .startObject("postDate")//
> .field("type", "date")
> .field("store", "yes")
> .field("index", "analyzed")//
> .endObject()// end post date
> .startObject("message") //
> .field("type", "string")
> .field("store", "yes")
> .field("index", "not_analyzed")
> .endObject() // end user field
> .endObject() // end properties
> .endObject() // end index type
> .endObject() // end mappings
> .endObject(); // end the container object
>
> IndexResponse response = this.client.prepareIndex(INDEX,INDEX_TYPE
> ).setSource(source)
> .setType(INDEX_TYPE).execute()
> .actionGet();
>
>
> I want to have the "message" field not analyzed, because later I want to
> use facets to obtain unique messages.
> Unfortunately my code seems to add just a document in index with the
> following structure:
> {
> "settings": {
> "number_of_shards": 1
> },
> "mappings": {
> "tweet": {
> "properties": {
> "user": {
> "type": "string",
> "store": "yes",
> "index": "analyzed"
> },
> "postDate": {
> "type": "date",
> "store": "yes",
> "index": "analyzed"
> },
> "message": {
> "type": "string",
> "store": "yes",
> "index": "not_analyzed"
> }
> }
> }
> }
> }
>
> Please help me to spot the error, it seems that mapping are not created.
> Thank you very much,
> Doru
>
>
--
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/38ae7a3e-b8ef-4a05-8f7a-5ff20917f85e%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.