我有几个处于负载平衡模式的ES服务器。当我对host1:9200执行查询时,host1,host2,host3之一可以处理此查询。是否有可能在ES响应中获得此主机名?
换句话说,我正在寻找MS SQL Server中的“选择myfield,@@ servername FROM表”的等效项。
谢谢
最佳答案
如果您使用的是http api,则可以从响应中的Host
header 获取主机名。
例如,如果使用curl进行查询,并使用-v
标志,它将显示响应 header ,您可以在其中找到发送响应的主机名,在本例中为localhost:
curl -XGET "http://localhost:9200/test/_search" -v -d '
{
"query": {"match_all":{}}
}'
* About to connect() to localhost port 9200 (#0)
* Trying ::1... connected
* Connected to localhost (::1) port 9200 (#0)
> GET /test/_search HTTP/1.1
> User-Agent: curl/7.21.4 (universal-apple-darwin11.0) libcurl/7.21.4 OpenSSL/0.9.8r zlib/1.2.5
> Host: localhost:9200
> Accept: */*
> Content-Length: 32
> Content-Type: application/x-www-form-urlencoded
>
< HTTP/1.1 200 OK
< Content-Type: application/json; charset=UTF-8
< Content-Length: 875
<
无论如何,请记住,如果将数据分成多个分片,则查询过程中可能包含多个主机。
关于elasticsearch - ES主机名作为响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20420162/