Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

index updateasync #48

Open
lhammond opened this issue Apr 28, 2014 · 1 comment
Open

index updateasync #48

lhammond opened this issue Apr 28, 2014 · 1 comment

Comments

@lhammond
Copy link

Hi Folks,
I'm a bit confused on how to update an indexed document.
It appears that I need to make a Map of the updated fields, but am unclear as to what the updateScript needs to be. Any tips?

 Map<String, Object> map = new HashMap<String,Object>();
 map.put("name", o.getName());
 map.put("description", o.getDescription());       
 map.put("tags", o.getTags());
 MyIndexClass a = new MyIndexClass(b);
 a.updateAsync(map, null);

0fd93ed

@hossein761
Copy link
Contributor

you should pass the update script in the a.updateASync(map,...) instead of null.
This is the method I use:

public static String generateUpdateScript(Set<String> fields) {
        StringBuilder updateStringBuilder = new StringBuilder();
        for(String field:fields){
            updateStringBuilder.append("ctx._source.")
                               .append(field)
                               .append("=")
                               .append(field)
                               .append(";");
        }
        return updateStringBuilder.toString();
    }

Pass the keys of your map as arguments. Remember that my script works only for replacing values and not any other fancy stuff that is mentioned in the ES api documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants