1

i have document in ElasticSearch

{
    "uuid" : 0,
    "StatusHistoryList" : [
        {
            "ArtWorkDate" : "2015-08-25T16:29:32.011+05:00",
            "ArtworkStatus" : "ACTIVE"
        }
    ]
}

i am adding this via code but having problem in adding this array field StatusHistoryList i am doing it like this

var xb:XContentBuilder=XContentFactory.jsonBuilder().startObject()
                        .field("uuid",artWork.getUuid)

      xb.startArray("StatusHistoryList")
      for(h<-history)
      {
        var date=h.date.toString()
        var artworkStatus=h.artworkStatus.toString
        xb.startObject()
        xb.field("ArtWorkDate",date)
        xb.field("ArtworkStatus",artworkStatus)
        xb.endObject()
      }
      xb.endArray()
      xb.endObject()

val bulkRequest=client.prepareBulk()
bulkRequest.add(client.prepareIndex("arteciatedb","artWork",artWork.uuid.toString())
        .setSource(xb)
)
val bulkResponse =bulkRequest.execute().actionGet()
if(bulkResponse.hasFailures())
{
 log.error("something is wrong here ") 
}}

on the console it is printing something is wrong here please help me where i am doing it wrong

UPDATE after the answer by Nimo here is the output printed on console

 controller ERROR - failed to executefailure in bulk execution:
[0]: index [arteciatedb], type [artWork], id [0], message [MapperParsingException[failed to parse [StatusHistoryList]]; nested: ElasticsearchIllegalArgumentException[unknown property [ArtWorkDate]]; ]
1
  • Do you get a more precise error message from bulkResponse? Commented Aug 25, 2015 at 14:45

1 Answer 1

1

To see where you are doing wrong:

var xb:XContentBuilder=XContentFactory.jsonBuilder().startObject()
                        .field("uuid",artWork.getUuid)

      xb.startArray("StatusHistoryList")
      for(h<-history)
      {
        var date=h.date.toString()
        var artworkStatus=h.artworkStatus.toString
        xb.startObject()
        xb.field("ArtWorkDate",date)
        xb.field("ArtworkStatus",artworkStatus)
        xb.endObject()
      }
      xb.endArray()
      xb.endObject()

val bulkRequest=client.prepareBulk()
bulkRequest.add(client.prepareIndex("arteciatedb","artWork",artWork.uuid.toString()).setSource(xb))
try { 
BulkResponse response=currentRequest.execute().actionGet();
 if (response.hasFailures()) {
 logger.error("failed to execute" + response.buildFailureMessage()); }
 } catch ( Exception e) { 
logger.error("Failed to process bulk",e);
 }
}

Now the error log would be more accurate and you can understand what's wrong from there.

Sign up to request clarification or add additional context in comments.

1 Comment

I think it's a simple mistake you should change var artworkStatus=h.artworkStatus.toString to var artworkStatus=h.artworkStatus.toString()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.