How To Solve Issues Related to Log – Could not find token document with refreshtoken

Prevent Your Next ELK Incident

Try our free Check Up to test if your ES issues are caused from misconfigured settings

Fix Issue

Updated: Jan-20

In-Page Navigation (click to jump) :

Opster Offer’s World-Class Elasticsearch Expertise In One Powerful Product
Try Our Free ES Check-Up   Prevent Incident

Troubleshooting background

To troubleshoot Elasticsearch log “Could not find token document with refreshtoken” it’s important to understand common problems related to Elasticsearch concepts: document, plugin. See detailed explanations below complete with common problems, examples and useful tips.

Document in Elasticsearch

Overview

A document is simply a json document that is stored in Elasticsearch index. It consists of one or more fields; where each field has its own data type. This field type defines the type of data that can be stored in the field such as integer, string, object. Document is schema-free, which means we do not require to specify schema before indexing document, when a field is indexed for the first time, its type is decided and set.

Examples:

Creating A document : to create a document in the users index.

POST  /users/_doc 
{
    "name" : "Petey",
    "lastname" : "Cruiser",
    "email" : "petey@gmail.com"
}

In the above request, we haven’t mentioned id for the document so index operation generates a unique ID for the document. Here _doc is the type of document. We can provide this type to user-defined type also where user index may store user type document.

POST  /users/_doc/1
{
    "name" : "Petey",
    "lastname" : "Cruiser",
    "email" : "petey@gmail.com"
}

In the above query, the document will be created with id 1.

You can use the below ‘GET’ query to get a document from the index using id

GET  /users/_doc/1

Bellow is the result containing the document (in _source field) with metadata:-

{
    "_index": "users",
    "_type": "_doc",
    "_id": "1",
    "_version": 1,    "_seq_no": 1,    "_primary_term": 1,
    "found": true,
    "_source": {
        "name": "Petey",
        "lastname": "Cruiser",
        "email": "petey@gmail.com"
    }
}
Notes

Starting version 7.0 types are deprecated, so for backward compatibility on version 7.x all docs are under type ‘_doc’, starting 8.x type will be completely removed from ES APIs

Plugin in Elasticsearch

What it is

A plugin is used to enhance the core functionalities of Elasticsearch. Elasticsearch provides some core plugins as a part of their release installation. In addition to those core plugins, it is possible to write your own custom plugins as well. There are several community plugins available on GitHub for various use cases.

Examples:
  • Get all the instructions for the plugin usage
sudo bin/elasticsearch-plugin -h
  • Installing S3 plugin using URL for storing Elasticsearch snapshots on S3
sudo bin/elasticsearch-plugin install repository-s3
  • Removing a plugin
sudo bin/elasticsearch-plugin remove repository-s3
  • Installing a plugin using the file path
sudo bin/elasticsearch-plugin install file:///path/to/plugin.zip

Notes:
  • Plugins are installed and removed using the elasticsearch-plugin script, which ships as a part of Elasticsearch installation and can be found inside the bin/ directory of the Elasticsearch installation path.
  • A plugin has to be installed on every node of the cluster and each of the nodes has to be restarted to make the plugin visible.
  • You can also download the plugin manually and then install it using the elasticsearch-plugin install command, providing the file name/path of the plugin’s source file.
  • When a plugin is removed, you will need to restart every elasticsearch node in order to complete the removal process.

Common Problems:
  • Managing permission issues during and after plugin installation is the most common problem. If Elasticsearch was installed using the deb or rpm package then the plugin has to be installed using the root user, or else you can install the plugin as the user that owns all of the Elasticsearch files.
  • In case of deb or rpm package installation, it is important to check the permission of the plugins directory after plugin installation and update the permission if it has been modified using the following command:
chown -R elasticsearch:elasticsearch path_to_plugin_directory 
  • If your Elasticsearch nodes are running in a private subnet without internet access, you cannot install a plugin directly. In this case, you can simply download the plugins at once and copy the files inside the plugins directory of the Elasticsearch installation path on every node. The node has to be restarted in this case as well.

Refresh in Elasticsearch


What it is

When indexing data, Elasticsearch requires a “refresh” operation to make indexed information available for search. This means that there is a time delay between indexing and the updated information actually becoming available for the client applications.

How it works

Index operations occur in memory. The operations are accumulated in a buffer until refreshed, which requires that the buffer be transferred to a newly created lucene segment. Refresh happens by default every second, but it is also possible to change this frequency for a given index, or directly request a refresh through the refresh api.

Examples

You can set the refresh interval on an index like this:

PUT /my_index/_settings
{
    "index" : {
        "refresh_interval" : "30s"
    }
}

You can use a value of -1 to represent “no refresh” but remember to set it back once you’ve finished indexing!

You can force a refresh on a given index like this:

POST my_index/_refresh

You can also force a refresh at the end of an index operation by adding an extra parameter in the url like this:

POST /my_index/_index?refresh=waitfor

In this case, the “waitfor” parameter will force the client to wait for the refresh to complete before returning (useful in scripts), or you can use “true” to force the refresh without keeping the script waiting.

Notes and good things to know:

Refreshing is resource-intensive, so you can increase indexing speed by reducing the refresh rate. You can do this temporarily if you need to reload a lot of data, or for some logging applications it is perfectly acceptable to have, say, a 30s latency before data actually becomes available.

Beware of the refresh interval when scripting or updating. Scripts often work faster than the refresh interval, so if necessary, you might need to call a refresh before retrieving or updating data in your scripts, or use the waitfor parameter while indexing as described above.


To help troubleshoot related issues we have gathered selected Q&A from the community and issues from Github , please review the following for further information :

1 Ring Oauth2 Refresh Token Cannot Co  

2Ing Postman To Access Firebase Rest  

Ring Security Oauth Full Authentica


Log Context

Log ”Could not find token document with refresh_token [{}]” classname is TokenService.java
We have extracted the following from Elasticsearch source code to get an in-depth context :

<pre class="wp-block-syntaxhighlighter-code">                         ActionListener.<SearchResponse>wrap(searchResponse -> {
                            if (searchResponse.isTimedOut()) {
                                attemptCount.incrementAndGet();
                                findTokenFromRefreshToken(refreshToken; listener; attemptCount);
                            } else if (searchResponse.getHits().getHits().length < 1) {
                                logger.info("could not find token document with refresh_token [{}]"; refreshToken);
                                onFailure.accept(invalidGrantException("could not refresh the requested token"));
                            } else if (searchResponse.getHits().getHits().length > 1) {
                                onFailure.accept(new IllegalStateException("multiple tokens share the same refresh token"));
                            } else {
                                listener.onResponse(new Tuple<>(searchResponse; attemptCount));




</pre>


About Opster

Opster identifies and predicts root causes of Elasticsearch problems, provides recommendations and can automatically perform various actions to prevent issues, optimize performance and save resources.

Learn more: Glossary | Blog| Troubleshooting guides | Error Repository

Need help with any Elasticsearch issue ? Contact Opster