Hi all,
Fairly new to Elasticsearch and hoping that some of you might be able to help me troubleshoot an attempt to use the python Elasticsearch-dsl to perform a search in a public database?
I am able to access the database with my API-key via either curl or Requests, but I can't get it to work with Elasticsearch-dsl. I imagine I must be forming my query poorly, but despite looking at the documentation I'm not sure what I'm doing wrong.
The following curl call:
curl -v -XPOST -u "user:pass" -H "Content-Type: application/json" \
http://distribution.virk.dk/cvr-permanent/virksomhed/_search -d '
{
"query": {
"bool": {
"must": [
{
"term": {
"Vrvirksomhed.cvrNummer": "35128417"
}
}
]
}
},
"_source":[
"Vrvirksomhed.virksomhedMetadata.nyesteNavn.navn"
]
}' | python -mjson.tool
Yields the correct data (a snippet):
{
"took": 7,
"timed_out": false,
"_shards": {
"total": 6,
"successful": 6,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 12.333591,
"hits": [
{
"_index": "cvr-v-20200115",
"_type": "_doc",
"_id": "4000333365",
"_score": 12.333591,
"_source": {
"Vrvirksomhed": {
"virksomhedMetadata": {
"nyesteNavn": {
"navn": "RAMB\u00d8LL DANMARK A/S"
}
}
}
}
}
]
}
}
But trying to follow the seach example given here to convert that query into Elasticsearch-dsl:
es = Elasticsearch(
['http://distribution.virk.dk/cvr-permanent/virksomhed/_search'],
http_auth=('user', 'password')
)
s = Search(using=es, index="cvr-v-20200115.Vrvirksomhed") \
.query("match", cvrNummer="35128417")
response = s.execute()
Yields a connection timeout
Traceback (most recent call last):
File "/Users/michh/opt/anaconda3/lib/python3.8/site-packages/urllib3/connection.py", line 159, in _new_conn
conn = connection.create_connection(
File "/Users/michh/opt/anaconda3/lib/python3.8/site-packages/urllib3/util/connection.py", line 84, in create_connection
raise err
File "/Users/michh/opt/anaconda3/lib/python3.8/site-packages/urllib3/util/connection.py", line 74, in create_connection
sock.connect(sa)
socket.timeout: timed out
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/michh/opt/anaconda3/lib/python3.8/site-packages/elasticsearch/connection/http_urllib3.py", line 255, in perform_request
response = self.pool.urlopen(
File "/Users/michh/opt/anaconda3/lib/python3.8/site-packages/urllib3/connectionpool.py", line 726, in urlopen
retries = retries.increment(
File "/Users/michh/opt/anaconda3/lib/python3.8/site-packages/urllib3/util/retry.py", line 386, in increment
raise six.reraise(type(error), error, _stacktrace)
File "/Users/michh/opt/anaconda3/lib/python3.8/site-packages/urllib3/packages/six.py", line 735, in reraise
raise value
File "/Users/michh/opt/anaconda3/lib/python3.8/site-packages/urllib3/connectionpool.py", line 670, in urlopen
httplib_response = self._make_request(
File "/Users/michh/opt/anaconda3/lib/python3.8/site-packages/urllib3/connectionpool.py", line 392, in _make_request
conn.request(method, url, **httplib_request_kw)
File "/Users/michh/opt/anaconda3/lib/python3.8/http/client.py", line 1255, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/Users/michh/opt/anaconda3/lib/python3.8/http/client.py", line 1301, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/Users/michh/opt/anaconda3/lib/python3.8/http/client.py", line 1250, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/Users/michh/opt/anaconda3/lib/python3.8/http/client.py", line 1010, in _send_output
self.send(msg)
File "/Users/michh/opt/anaconda3/lib/python3.8/http/client.py", line 950, in send
self.connect()
File "/Users/michh/opt/anaconda3/lib/python3.8/site-packages/urllib3/connection.py", line 187, in connect
conn = self._new_conn()
File "/Users/michh/opt/anaconda3/lib/python3.8/site-packages/urllib3/connection.py", line 164, in _new_conn
raise ConnectTimeoutError(
urllib3.exceptions.ConnectTimeoutError: (<urllib3.connection.HTTPConnection object at 0x7fc9b44f2d00>, 'Connection to distribution.virk.dk timed out. (connect timeout=10)')
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/michh/opt/anaconda3/lib/python3.8/site-packages/elasticsearch_dsl/search.py", line 715, in execute
self, es.search(index=self._index, body=self.to_dict(), **self._params)
File "/Users/michh/opt/anaconda3/lib/python3.8/site-packages/elasticsearch/client/utils.py", line 347, in _wrapped
return func(*args, params=params, headers=headers, **kwargs)
File "/Users/michh/opt/anaconda3/lib/python3.8/site-packages/elasticsearch/client/__init__.py", line 1830, in search
return self.transport.perform_request(
File "/Users/michh/opt/anaconda3/lib/python3.8/site-packages/elasticsearch/transport.py", line 417, in perform_request
self._do_verify_elasticsearch(headers=headers, timeout=timeout)
File "/Users/michh/opt/anaconda3/lib/python3.8/site-packages/elasticsearch/transport.py", line 606, in _do_verify_elasticsearch
raise error
File "/Users/michh/opt/anaconda3/lib/python3.8/site-packages/elasticsearch/transport.py", line 569, in _do_verify_elasticsearch
_, info_headers, info_response = conn.perform_request(
File "/Users/michh/opt/anaconda3/lib/python3.8/site-packages/elasticsearch/connection/http_urllib3.py", line 280, in perform_request
raise ConnectionError("N/A", str(e), e)
elasticsearch.exceptions.ConnectionError: ConnectionError((<urllib3.connection.HTTPConnection object at 0x7fc9b44f2d00>, 'Connection to distribution.virk.dk timed out. (connect timeout=10)')) caused by: ConnectTimeoutError((<urllib3.connection.HTTPConnection object at 0x7fc9b44f2d00>, 'Connection to distribution.virk.dk timed out. (connect timeout=10)'))
Thanks in advance for your help!