node.jselasticsearchkuzzle

How to use elasticsearch query with searchUsers function in Kuzzle?


i set a property called type in some users with the kuzzle console, now i want to search for user who have the type set to user so i use a query for searching user. Here is my code:

const resultUsers = await kuzzle.security.searchUsers({
  query: {
    term: {
      type: "user"
    }
  }
})
console.log(resultUsers)

I also tried with this query too:

query: {
  term: {
    "content.type": "user"
  }
}

and this one:

query: {
  term: {
    "_source.type": "user"
  }
}

But the function always return 0 users. Can someone explain me why please ?


Solution

  • You can only search for properties that have been properly indexed.

    You can check the mappings of the internal users collection with the security:getUserMapping API action or with the Admin Console.

    Then you need to modify the mappings to include your new property:

      {
        "properties": {
          "type": { "keyword" }
        }
      }
    

    For this, you can use the security:updateUserMapping API action or again, the Admin Console.