How to access a specific array object via object property in mvel?

I'm attempting to use the new update function and attachment plugin to
update a specific file object with the contents of the attachment. My
mapping looks like this:

where "files" is an array of file objects. I've verified the following
works:

UpdateResponse updateResponse = new UpdateRequestBuilder(transportClient,
Index.THREAD.getName(),
Index.THREAD.getType(),
String.valueOf(threadID))
.setScript("ctx._source.files[0].content = content")
.addScriptParam("content", attachment)
.execute().actionGet();

But I'd like to do something like ctx._source.files[fileID].content =
content to update a specific file object by it's fileID property. I'm
flexible on changing my mapping at this point in order to get this to work.

The best way I can think about is with a more complex script, where you
have the file id on each file array element (based on the mappings, it
looks like you do), iterate through the files, find the ones that match the
file id, and then update its content.

On Wed, Mar 14, 2012 at 6:47 PM, Shane Witbeck shane@digitalsanctum.comwrote:

I'm attempting to use the new update function and attachment plugin to
update a specific file object with the contents of the attachment. My
mapping looks like this:

thread.json · GitHub

where "files" is an array of file objects. I've verified the following
works:

UpdateResponse updateResponse = new UpdateRequestBuilder(transportClient,
Index.THREAD.getName(),
Index.THREAD.getType(),
String.valueOf(threadID))
.setScript("ctx._source.files[0].content = content")
.addScriptParam("content", attachment)
.execute().actionGet();

But I'd like to do something like ctx._source.files[fileID].content =
content to update a specific file object by it's fileID property. I'm
flexible on changing my mapping at this point in order to get this to work.

Great. Is there an example of what that looks like?

On Friday, March 16, 2012 12:59:27 PM UTC-4, kimchy wrote:

The best way I can think about is with a more complex script, where you
have the file id on each file array element (based on the mappings, it
looks like you do), iterate through the files, find the ones that match the
file id, and then update its content.

On Wed, Mar 14, 2012 at 6:47 PM, Shane Witbeck shane@digitalsanctum.comwrote:

I'm attempting to use the new update function and attachment plugin to
update a specific file object with the contents of the attachment. My
mapping looks like this:

thread.json · GitHub

where "files" is an array of file objects. I've verified the following
works:

UpdateResponse updateResponse = new UpdateRequestBuilder(transportClient,
Index.THREAD.getName(),
Index.THREAD.getType(),
String.valueOf(threadID))
.setScript("ctx._source.files[0].content = content")
.addScriptParam("content", attachment)
.execute().actionGet();

But I'd like to do something like ctx._source.files[fileID].content =
content to update a specific file object by it's fileID property. I'm
flexible on changing my mapping at this point in order to get this to work.

No..., though you can use javascript as well as the scripting instead of
mvel if it makes things simpler (using the lang-javascript plugin).

On Fri, Mar 16, 2012 at 10:47 PM, Shane Witbeck shane@digitalsanctum.comwrote:

Great. Is there an example of what that looks like?

On Friday, March 16, 2012 12:59:27 PM UTC-4, kimchy wrote:

The best way I can think about is with a more complex script, where you
have the file id on each file array element (based on the mappings, it
looks like you do), iterate through the files, find the ones that match the
file id, and then update its content.

On Wed, Mar 14, 2012 at 6:47 PM, Shane Witbeck shane@digitalsanctum.comwrote:

I'm attempting to use the new update function and attachment plugin to
update a specific file object with the contents of the attachment. My
mapping looks like this:

https://gist.github.com/**2037762 https://gist.github.com/2037762

where "files" is an array of file objects. I've verified the following
works:

UpdateResponse updateResponse = new UpdateRequestBuilder(**
transportClient,
Index.THREAD.getName(),
Index.THREAD.getType(),
String.valueOf(threadID))
.setScript("ctx._source.files[**0].content = content")
.addScriptParam("content", attachment)
.execute().actionGet();

But I'd like to do something like ctx._source.files[fileID].**content =
content to update a specific file object by it's fileID property. I'm
flexible on changing my mapping at this point in order to get this to work.