【问题标题】:How to search exact index (not index pattern) in elasticsearch eland?如何在 elasticsearch eland 中搜索精确索引(不是索引模式)?
【发布时间】:2022-01-13 00:26:08
【问题描述】:

我正在使用 eland 调用弹性搜索数据。文档很简单,我可以实现它,但是在搜索索引时,它使用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"}},
                ]
        }

    }

# 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)

# But, I do not get results (but ReadTimeoutError) if I connect to 'my_index' index via localhost Elasticsearch node 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 中搜索准确的索引字符串?

来源:

【问题讨论】:

    标签: python elasticsearch pyelasticsearch eland


    【解决方案1】:

    无论您是否在索引模式中使用通配符,Eland 与 Elasticsearch 的通信方式都是相同的。所以这让我认为您的请求超时是由于连接性或请求太大而无法在 Elasticsearch 上及时处理(您是否有完整的超时错误回溯?)

    也许增加 Elasticsearch 客户端构造函数上的 request_timeout 值会有所帮助?

    (免责声明:我是 Eland 的维护者,为 Elastic 工作)

    【讨论】:

    • 是的,请求太大,无法及时处理。那就是我正在搜索的索引正在作为通配符进行搜索。如果是通过 pyelasticsearch(而不是 eland)搜索相同的索引,我会得到结果。但是,一旦我使用 eland,ReadTimeoutError 就会启动 bc/索引说 abc 正在被搜索为 *abc*
    • 我只是用更多细节更新了这个问题。请让我知道我的选择。
    • 您对这个问题有任何更新吗?虽然这不是一个好习惯,但我再次发布了一个问题;第一天未回答的 b/c 问题通常不予回答。请看stackoverflow.com/questions/70685986/…
    猜你喜欢
    • 2021-03-27
    • 2022-06-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-02
    • 2019-09-19
    • 2015-02-12
    • 2016-11-26
    相关资源
    最近更新 更多