1

I've got a problem while trying to connect to an elasticsearch API. The API expect an bearer token, but the NEST lybrary only provides a basic authentication and I've got to pass a custom header as well. So, did anybody have to face this problem?? How to pass custom headers?!

Thanks

enter image description here

3 Answers3

6

You can add headers that should be added to all requests on ConnectionSettings

var pool = new SingleNodeConnectionPool(new Uri("http://localhost:9200"));
var connectionSettings = new ConnectionSettings(pool)
    .GlobalHeaders(new NameValueCollection 
    { 
        { "Authorization", "Bearer fnoi3nfion3fn00jr0j1r0" } 
    });

var client = new ElasticClient(connectionSettings);
Russ Cam
  • 124,184
  • 33
  • 204
  • 266
0

Actually I was getting a mistaken concept. Actually I'm interacting with an API wich encapsolate the elasticsearch and just use the elasticsearch query sintax, so I didn't need to use NEST, the elasticsear package, to connect with it. And I just got to interact it with a simple http call.

Anyway, thanks Russ

-1

you can add any header to your request:

req.Headers.Add("CustomeKey", CustomeData);
Ehsan Zargar Ershadi
  • 24,115
  • 17
  • 65
  • 95
  • I'm not using httclient or something similar. I'm using NEST, the elasticsearch package, so I can use it. Where did you come with req ??? – Bruno Lopes Oct 20 '17 at 14:35