3

I have successful setup the elasticsearch x-pack security. And I am planning to use the generated token to limit requests. I generated token following this page: https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-tokens.html And tested it in curl:

curl -H "Authorization: Bearer k7vvAiCHUtrYVNNuLFPv***************EOIXQi+L7FevycU=" http://localhost:9200/plugin/database/_search?q=*:*

It is working well. But when I try to use the same token in my node.js controller (using elasticsearch.js), I do not know where I should put it, for instance in "client.index":

return client.index({
                index: indexName,
                type: typeName,
                body: {
                    authorization: "Bearer k7vvAiCHUtrYV*****XQi+L7FevycU=",

                    workspace: content
                }
            });

It does not work, and returning error msg:

<- 401
  {
    "error": {
      "root_cause": [
        {
          "type": "security_exception",
          "reason": "missing authentication token for REST request [/plugin/database]",
          "header": {
            "WWW-Authenticate": "Basic realm=\"security\" charset=\"UTF-8\""
          }
        }
      ],
      "type": "security_exception",
      "reason": "missing authentication token for REST request [/plugin/database]",
      "header": {
        "WWW-Authenticate": "Basic realm=\"security\" charset=\"UTF-8\""
      }
    },
    "status": 401
  }

So how should I pass this generated token in my node.js request to elasticsearch?

user4816915
  • 123
  • 7

0 Answers0