0

I have a following document

{
  "_index" : "Testdb",
  "_type" : "artWork",
  "_id" : "0",
  "_version" : 1,
  "found" : true,
  "_source":{"uuid":0,"ArtShare":{"TotalArtShares":0,"pricePerShare":0,"ArtworkUuid":12,"AvailableShares":0,"SoldShares":0},"StatusHistoryList":[{"ArtWorkDate":"2015-08-26T13:20:17.725+05:00","ArtworkStatus":"ACTIVE"}]}
}

i want to access/retrieve the value of ArtShare and its attributes and values of array StatusHistoryList

i am doing like this

val get=client.prepareGet("Testdb","artWork",Id.toString())
        .setOperationThreaded(false)
        .setFields("uuid","ArtShare","StatusHistoryList"
            )
        .execute()
        .actionGet()
        if(get.isExists())
        {
        uuid=get.getField("uuid").getValue.toString().toInt
       //how to fetch `artShare` whole nested document and array elements `StatusHistoryListof`  
     }

UPDATE if i do this

 val get=client.prepareGet("Testdb","artWork",Id.toString())
            .setOperationThreaded(false)
            .setFields("uuid","ArtShare","StatusHistoryList"
                ,"_source","ArtShare.TotalArtShares")
            .execute()
            .actionGet()
            if(get.isExists())
            {
            uuid=get.getField("uuid").getValue.toString().toInt
           var totalShares= get.getField("ArtShare.TotalArtShares").getValue.toString().toInt 
         }

then following exception thrown

org.elasticsearch.ElasticsearchIllegalArgumentException: field [ArtShare] isn't a leaf field
    at org.elasticsearch.index.get.ShardGetService.innerGetLoadFromStoredFields(ShardGetService.java:368)
    at org.elasticsearch.index.get.ShardGetService.innerGet(ShardGetService.java:210)
    at org.elasticsearch.index.get.ShardGetService.get(ShardGetService.java:104)
    at org.elasticsearch.action.get.TransportGetAction.shardOperation(TransportGetAction.java:104)
    at org.elasticsearch.action.get.TransportGetAction.shardOperation(TransportGetAction.java:44)
    at org.elasticsearch.action.support.single.shard.TransportShardSingleOperationAction$ShardTransportHandler.messageReceived(TransportShardSingleOperationAction.java:297)
    at org.elasticsearch.action.support.single.shard.TransportShardSingleOperationAction$ShardTransportHandler.messageReceived(TransportShardSingleOperationAction.java:280)
    at org.elasticsearch.transport.netty.MessageChannelHandler$RequestHandler.doRun(MessageChannelHandler.java:279)
    at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:36)

please guide me how to fetch these values

2
  • For ArtShare it should work like this : "ArtShare.TotalArtShares","ArtShare.pricePerShare","ArtShare.ArtworkUuid" Commented Aug 26, 2015 at 10:52
  • no its not working it throws exception please see my edited question Commented Aug 26, 2015 at 11:47

1 Answer 1

2

Yeah Actually the problem is that you have mentioned both "ArtShare" and "ArtShare.TotalArtShares" in the fields array. So it throws exception as you have already retrieved complete ArtShare object.

So please mention the fields that you want, If you want specified nested values then no need to access complete parent object.

Try this:

val get=client.prepareGet("Testdb","artWork",Id.toString())
        .setOperationThreaded(false)
        .setFields("uuid","StatusHistoryList",
            "ArtShare.TotalArtShares")
        .execute()
        .actionGet()
        if(get.isExists())
        {
        uuid=get.getField("uuid").getValue.toString().toInt
       var totalShares= get.getField("ArtShare.TotalArtShares" 
     }

And if you want complete "ArtShare" object then simply write :

val get=client.prepareGet("Testdb","artWork",Id.toString())
    .setOperationThreaded(false)
    .setFields("uuid","ArtShare","StatusHistoryList"
        )
    .execute()
    .actionGet()
    if(get.isExists())
    {
    uuid=get.getField("uuid").getValue.toString().toInt
   //how to fetch `artShare` whole nested document and array elements `StatusHistoryListof`  
 }
Sign up to request clarification or add additional context in comments.

5 Comments

when i do this log.info("getting artshare TotalArtShares values ",get.getField("ArtShare.TotalArtShares")) it returns null with setField("uuid","StatusHistoryList", "ArtShare.TotalArtShares") but values exits when i do curl get its not null there ...why is this happening ?
May be you should try getField("ArtShare"). This will help you get the json of ArtShare and you can retrieve the "TotalArtShares" from that.
no its working with ArtShare.TotalShares now thank you do you have any idea how can i retrieve the StatusHistoryList array ?
Please specify what is problem you getting with StatusHistoryList because if you add this to fields it must be in the result.
i have posted this issue here please look at it and help me please i wil be very thankful to you stackoverflow.com/questions/32269751/…

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.