fusionauth

FusionAuth ElasticSearch for users with expiry field


I am trying to list all users that have the expiry field set.

I want to create a list of all that are already expired and the ones that have it set together with WHEN they will expire.

Step #1 for that is actually getting all the users. However, I am not managing using the query the docs are suggesting:

POST request:

{
"search": {
    "numberOfResults": 50,
    "query": "{\"exists\": {\"field\": \"expiry\"}}",
    "sortFields": [
        {
            "missing": "_first",
            "name": "email",
            "order": "asc"
        }
    ],
    "startRow": 0
}
}

This returns no matches. I am sure that I have at least 3 users with an expiry field set. The ones without expiry the field is not even present.

I tried the inverse query:

"query": "{\"bool\": {\"must_not\": {\"exists\": {\"field\": \"user.id\"}}}}",

which got me all users. I also tried a simpler query to validate that it was returning something and it is.

The expiry is an element that is on the root as one can see on the FusionAuth docs:

{
  "user": {
    "birthDate": "1976-05-30",
    "data": {
      "displayName": "Johnny Boy",
      "favoriteColors": [
        "Red",
        "Blue"
      ]
    },
    "email": "example@fusionauth.io",
    "encryptionScheme": "salted-sha256",
    "factor": 24000,
    "expiry": 1571786483322,
    "firstName": "John",
    "fullName": "John Doe",
    "imageUrl": "http://65.media.tumblr.com/tumblr_l7dbl0MHbU1qz50x3o1_500.png",
    "lastName": "Doe",
    "memberships": [{
...

Can anyone point to where I am missing something? Is this a problem with the query?


Solution

  • expiry is not indexed, so you won't be able to search on it. We should update the docs to indicate which fields are indexed, but until then you can view the elasticsearch index to see that.

    curl -XGET http://elasticsearchhost:port/fusionauth_user/_mapping
    

    You can file a feature request to get expiry added to the indexed fields: https://github.com/fusionauth/fusionauth-issues/issues

    Here's a forum post on the same topic: https://fusionauth.io/community/forum/topic/1095/how-can-i-see-which-fields-are-indexed