Indexing using XContentBuilder


(Sanjay Reddy) #1

Hi,

I got stuck at a point while indexing the data.

The format that I'm indexing the data is :
(Code followed by the result)

 XContentFactory.jsonBuilder().startObject()
.startObject("tweet")
    .startObject("properties")
        .filed("name","lakshman")
        .startObject("message")
            .field("type", "string")
            .field("store", "yes")
            .field("index", "analyzed")
            .field("null_value", "na")
        .endObject()
    .endObject()
.endObject()

.endObject()

"tweet":{
	"name":"lakshman"
	"message"{
		"type", "string",
		"store", "yes",
		"index", "analyzed"
		"null_value", "na"
         }
    }

Now, If I index the record "tweet" again with different name like "name":"sanjay" and remaining data as same, then both the records should come like:

"tweet":{
        "name":"lakshman"
	"message"{
		"type", "string",
		"store", "yes",
		"index", "analyzed"
		"null_value", "na"
         }
	
	"name":"sanjay"
	"message"{
		"type", "string",
		"store", "yes",
		"index", "analyzed"
		"null_value", "na"
         }
   }

Is this possible. If yes, please help me in achieving this.

Thanks & Regards,
Sanjay Reddy.


(Geunmoon Oh) #2

how about using nested object field like below?

{
  "tweet": [
    {
      "name": "lakshman",
      "message": {
        "type": "string",
        "store": "yes",
        "index": "analyzed",
        "null_value": "na"
      }
    },
    {
      "name": "sanjay",
      "message": {
        "type": "string",
        "store": "yes",
        "index": "analyzed",
        "null_value": "na"
      }
    }
  ]
}

(system) #3