'"curl: (52) Empty reply from server" / timeout when querying ElastiscSearch

I've ran into an annoying issue with my ElasticSearch (Version 1.5.2): Queries immediately return timeout (when I used python's Requests) or

curl: (52) Empty reply from server

when I used curl.

This only happened when the expected output was large. When I sent a similar (but smaller) query, it came back just fine.

what's going on here? and how can I overcome this?



Solution 1:[1]

This issue was caused by Elastic running out of memory: it simply can't hold all the documents in memory. Unfortunately there's no explicit error code for this case.

There are a bunch of options to work around this (besides adding more memory):

  1. You can tell Elastic to not attach the source, by specifying "_source: false". The results would then just list the relevant documents (and you would need to retrieve them).
  2. You could use "source filtering" to return just part of the documents, if you dont need the whole thing - that worked for me.
  3. You can also just split your query into a bunch of sub-queries. not pretty, but it would do the trick.

Solution 2:[2]

An other explanation can be making http request when ssl/security is activated on the cluster.

In this case use

curl -X GET "https://localhost:9200/_cluster/health?wait_for_status=yellow&timeout=50s&pretty" --key certificates/elasticsearch-ca.pem  -k -u elasticuser

Solution 3:[3]

just open

sudo nano  /etc/elasticsearch/elasticsearch.yml

and replace this setting with false
# Enable security features
xpack.security.enabled: false

Solution 4:[4]

I meet with the same issue on Elasticsearh 8.1.3, which is the latest version. I fixed this issue by changing the following setting from true to false in the /config/elasticsearch.yml file:

# Enable security features
xpack.security.enabled: false

I installed elastic by downloading the tar file, and unzip it, then going to the folder of elasticsearch, and running the following command:

./bin/elasticsearch

The first time you run this command, it will change the elasticsearch.yml file with the following content, which means it's a default secruity setting auto generated:

#----------------------- BEGIN SECURITY AUTO CONFIGURATION -----------------------
#
# The following settings, TLS certificates, and keys have been automatically      
# generated to configure Elasticsearch security features on 01-05-2022 06:59:12
#
# --------------------------------------------------------------------------------

# Enable security features
xpack.security.enabled: true

xpack.security.enrollment.enabled: true

# Enable encryption for HTTP API client connections, such as Kibana, Logstash, and Agents
xpack.security.http.ssl:
  enabled: true
  keystore.path: certs/http.p12

# Enable encryption and mutual authentication between cluster nodes
xpack.security.transport.ssl:
  enabled: true
  verification_mode: certificate
  keystore.path: certs/transport.p12
  truststore.path: certs/transport.p12
# Create a new cluster with the current node only
# Additional nodes can still join the cluster later
cluster.initial_master_nodes: ["DaMings-MacBook-Pro.local"]

# Allow HTTP API connections from localhost and local networks
# Connections are encrypted and require user authentication
http.host: [_local_, _site_]

# Allow other nodes to join the cluster from localhost and local networks
# Connections are encrypted and mutually authenticated
#transport.host: [_local_, _site_]

#----------------------- END SECURITY AUTO CONFIGURATION -------------------------

Solution 5:[5]

In version 6.2, there are more strict checking.

for example:

curl -XPUT -H'Content-Type: application/json' 'http://localhost:9200/us/user/2?pretty=1' -d '{"email" : "[email protected]", "name" : "Mary Jones","username" : "@mary"}'
curl: (52) Empty reply from server

if you remove =1:

curl -XPUT -H'Content-Type: application/json' 'http://localhost:9200/us/user/2?pretty' -d '{"email" : "[email protected]", "name" : "Mary Jones","username" : "@mary"}'
{
  "_index" : "us",
  "_type" : "user",
  "_id" : "2",
  "_version" : 1,
  "result" : "created",
  "_shards" : {
    "total" : 2,
    "successful" : 1,
    "failed" : 0
  },
  "_seq_no" : 0,
  "_primary_term" : 1
}

it works!

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 FuzzyAmi
Solution 2 NanoPish
Solution 3 Syscall
Solution 4 David Liu
Solution 5 Preston