Skip to content
This repository was archived by the owner on Sep 28, 2022. It is now read-only.

Add document:updateByQuery#76

Merged
y-abs merged 10 commits into
3-devfrom
KZL-1350-document-updateByQuery
Apr 8, 2020
Merged

Add document:updateByQuery#76
y-abs merged 10 commits into
3-devfrom
KZL-1350-document-updateByQuery

Conversation

@y-abs
Copy link
Copy Markdown
Contributor

@y-abs y-abs commented Mar 18, 2020

What does this PR do ?

This PR implements the updateByQuery method with its unit tests.

How should this be manually tested?

Clone this branch and run unit tests
./gradlew test

When it succeed, compile it

./gradlew jar

Initiate another java project by adding the compiled SDK as a dependency.

Then, run Kuzzle, create an index nyc-open-data and a yellow-taxi collection in the admin console. Create 5 documents with 3 containing field {"key":"value"}.
Finally, run this code

import io.kuzzle.sdk.*;
import io.kuzzle.sdk.Options.KuzzleOptions;
import io.kuzzle.sdk.Options.Protocol.WebSocketOptions;
import io.kuzzle.sdk.Protocol.WebSocket;

import java.util.concurrent.ConcurrentHashMap;

public class updateByQueryDocument {
    private static Kuzzle kuzzle;

    public static void main(String[] args) {
        WebSocketOptions opts = new WebSocketOptions();
        opts.setAutoReconnect(true).setConnectionTimeout(42000);

        try {
            WebSocket ws = new WebSocket("localhost", opts);

            kuzzle = new Kuzzle(ws, (KuzzleOptions) null);

            kuzzle.connect();
           
            ConcurrentHashMap<String, Object> searchQuery = new ConcurrentHashMap<>();
            ConcurrentHashMap<String, Object> match = new ConcurrentHashMap<>();
            match.put("key", "value");
            searchQuery.put("match", match);
            ConcurrentHashMap<String, Object> changes = new ConcurrentHashMap<>();
            changes.put("key", "awesome-value");

            UpdateOptions ops = new UpdateOptions();
            ops.setSource(true);
            ConcurrentHashMap<String, ArrayList<Object>> result = kuzzle.getDocumentController().updateByQuery("nyc-open-data", "yellow-taxi", searchQuery, changes, ops).get();
            System.out.println(result);
           
        }  catch (Exception e) {
            e.printStackTrace();
        }

        kuzzle.disconnect();
    }
};

Check the response

@y-abs y-abs self-assigned this Mar 18, 2020
| Arguments | Type | Description |
| ------------------ | -------------------------------------------- | --------------------------------- |
| `waitForRefresh` | <pre>Boolean</pre> | If set to `true`, Kuzzle will wait for the persistence layer to finish indexing|
| `retryOnConflict` | <pre>Integer</pre> | The number of times the database layer should retry in case of version conflict |
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This option is not part of the updateByQuery API

Copy link
Copy Markdown
Contributor

@scottinet scottinet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment above

@y-abs y-abs requested a review from scottinet April 2, 2020 13:00
@y-abs y-abs merged commit a9aaa86 into 3-dev Apr 8, 2020
@y-abs y-abs deleted the KZL-1350-document-updateByQuery branch April 8, 2020 07:40
@jenow jenow mentioned this pull request May 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants