如何在 elasticsearch eland 中搜索精确索引(而不是索引模式) - 已更新?

How to search exact index (not index pattern) in elasticsearch eland - updated?

我正在使用 eland 调用 elasticsearch 数据。文档很简单,我能够实现它,但是在搜索索引时,它使用 es_index_pattern 搜索索引字符串,这基本上是一个通配符(它也在文档中说明)。

from elasticsearch import ElasticSearch
import eland as ed

es = Elasticsearch(hosts="myhost", "port":0000)

search_body={
    "bool":{
            "filter":[
                {"exists": {"field": "customer_name"}},
                {"match_phrase": {"city": "chicago"}},
                ]
        }

    }

# Success : I am able to get the results if I search the index through "elasticsearch" api. Tried this repetitively and it works every time
results = es.search(index="my_index", body=search_body)

# Failure : But, I do not get results (but ReadTimeoutError) if I connect to 'my_index' index via the same localhost Elasticsearch using Eland
df = ed.DataFrame(es_client=es, es_index_pattern = 'my_index')

我必须手动输入错误消息,因为我无法将错误复制到我正在使用的环境之外。另外,我的主机和端口会有所不同

...
  File ".../elasticsearch/transport.py", line 458, in perform_request
    raise e
  File "......elasticsearch/transport.py", line 419, in perform_request
  File "..... /elasticsearch/connection/http_urllib3.py", line 275, in perform_request
    raise ConnectionTimeout("TIMEOUT", str(e), e)
elasticsearch.exceptions.ConnectionTimeout: ConnctionTimeout caused by - ReadTimeoutError(HTTPSConnectionPool(host=myhost', port=0000): Read timed out. (read timeout=10)

我认为通过 elasticsearch 搜索能够得到结果,因为它调用的是准确的索引名称,因此不会 运行 超时。

但是,Eland 更像是使用 es_index_pattern,因此使用 my_index 作为通配符,即 *my_index*,因此我必须 运行 变成 ReadTimeOutError.

我查看了源代码,看看是否有什么我可以做的,所以 Eland 没有搜索索引作为模式,而是精确匹配。但是,我在文档和源代码中都看不到搜索确切索引的选项。

如何在 Eland 中搜索准确的索引字符串?

来源:

还有 posted this on Github 但我会在这里复制:

搜索精确索引只需要传递精确索引名称,不使用通配符:

import eland as ed
from elasticsearch import Elasticsearch

client = Elasticsearch(...)

client.index(index="test", document={"should": "seethis"})
client.index(index="test1", document={"should": "notseethis"})
client.index(index="1test", document={"should": "notseethis"})
client.indices.refresh(index="*test*")

df = ed.DataFrame(client, es_index_pattern="test")
print(df.to_pandas())

上面的输出符合预期:

                       should
SNTTnH4BRC8cqQQMds-V  seethis

选项中的 pattern 单词并不意味着我们正在使用通配符,它​​是我们在 search 和索引 API 中发送到 Elasticsearch 的模式。