kuzzleio / kuzzle

Open-source Back-end, self-hostable & ready to use - Real-time, storage, advanced search - Web, Apps, Mobile, IoT -
https://kuzzle.io
Apache License 2.0
1.43k stars 123 forks source link

Update Kuzzle Users form ES #2038

Closed foralobo closed 3 years ago

foralobo commented 3 years ago

Expected Behavior

When I execute a massive update to users from ES Api (_update_by_query), data must be updated

Current Behavior

The data seems up to date but in reality it is not

Possible Solution

Steps to Reproduce

  1. I Create un user in the kuzzle console
  2. Call API _update_by_query from ES, it works but...
  3. until I don't modify the content of user manually.
  4. If I do it, when I again call the api from ES, api respond with success
  5. Go to console, users section
  6. If I expand data user in table, there are the updated data from ES... but...
  7. when I go to Edit User (icon) -> Custom, the data is one I had manually updated and it will not change more until I change data from this section.
  8. In every case, if I call getCurrentUser () API, I get data inserted manually end not the one updated from ES

Context (Environment)

Kuzzle version: (I am in testing with get started docker app) 2.10.4 Node.js version: (I am in testing with get started docker app) v12.18.1 SDK version: JS SDK v. (but is not a problem of SDK)

Aschen commented 3 years ago

Hi @foralobo ,

Kuzzle simply query ES to get the user documents so if you modify them with an ES query Kuzzle will then use the modified documents.

Can you show your ES query so I can try to reproduce?

foralobo commented 3 years ago

Of course,

POST /%%kuzzle.users/_update_by_query
{

  "script": {
    "source": "ctx._source.forasChat = params.forasChat",
    "params": {
      "forasChat": {

      "settings": {
        "blocked": {
          "list": []
        },
        "online": {
          "all": true,
          "exceptions": []
        }

      }
      }
    }
  }
}

I use kibana to execute this script... and this is result of my query!!

Schermata 2021-04-06 alle 14 01 17

Then I fo to console:

end expand my user "pippo":

Schermata 2021-04-06 alle 14 01 49

It's correct!!

but when I go to manual update of my user "pippo":

Schermata 2021-04-06 alle 14 02 00

IMPORTANT: this is because I, before execute query, had edited manually content of "pippo" from console.

Aschen commented 3 years ago

I tried to reproduce but I have the expected behavior:

curl -X POST -H  "Content-Type: application/json" "localhost:9200/%%kuzzle.users/_update_by_query" --data '{

  "script": {
    "source": "ctx._source.forasChat = params.forasChat",
    "params": {
      "forasChat": {

      "settings": {
        "blocked": {
          "list": []
        },
        "online": {
          "all": true,
          "exceptions": []
        }

      }
      }
    }
  }

image

image

Did you try to reload the admin console?

foralobo commented 3 years ago

Are you try to edit From console the content of user and then.. re-execute the query?

foralobo commented 3 years ago

Did you try to reload the admin console?

Yes I try to reload console and also the server. But no changes happen!! :(

Aschen commented 3 years ago

Ok I found the problem.

Kuzzle cache users content in Redis to avoid a request to the database when it comes to load the profileIds field who contain the information needed by the permission system.

You need to reset the internal cache after your query to Elasticsearch, you can use the admin:resetCache action.

Example with Kourou:

kourou admin:resetCache -a database=internalCache
foralobo commented 3 years ago

Great!!!! It Works.... thank you very much