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

Update API: Allow to upsert, provide a doc and index it if the doc does not exists #2008

Closed
kimchy opened this issue Jun 7, 2012 · 9 comments

Comments

@kimchy
Copy link
Member

kimchy commented Jun 7, 2012

Here is a sample:

curl -XPUT localhost:9200/test

curl -XPOST 'localhost:9200/test/type1/1/_update' -d '{
    "script" : "ctx._source.counter += count",
    "params" : {
        "count" : 4
    },
    "upsert" : {
        "counter" : 0
    }
}'

curl -XGET localhost:9200/test/type1/1
@kimchy kimchy closed this as completed in 9905eab Jun 8, 2012
@MrJohnsson77
Copy link

Wonderfull, great work! :-)

@mattweber
Copy link
Contributor

Would it be possible to use this new "doc" as the document containing the updated fields without needing to use a script?

Taking a quick look though the code it seems like it might be possible if we check that no "script" is set then pull the updated source back out of the new IndexRequest. I imagine as we need to get it as a map but it looks like we can only get bytes currently. Once we have the sources we can merge and index.

@kimchy
Copy link
Member Author

kimchy commented Jun 12, 2012

The problem here is how to "merge" that new doc values into the updated doc? Simple fields can be overridden or appended, but what happens with array values and the like? we can decide that its a simple override and thats it.

@Paikan
Copy link
Contributor

Paikan commented Jun 12, 2012

I think a simple override would be nice, more complex operations would be done using scripts.

@mattweber
Copy link
Contributor

Yea I think a simple override would be fine (just like the partial update plugin). If someone needs something more advanced they can use a script like Paikan said.

@JW200
Copy link

JW200 commented Nov 6, 2012

It would be nice to have conditional insert so that insert happens only if the record does not exist.

@imotov
Copy link
Contributor

imotov commented Nov 6, 2012

Is Index with op_type=create the functionality you are looking for?

@JW200
Copy link

JW200 commented Nov 7, 2012

Yep it is. Thanks

@JW200
Copy link

JW200 commented Nov 7, 2012

Are there any other values that op_type can take besides create?

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

No branches or pull requests

6 participants