问题标签 [elasticsearch-py]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
python - What is the Elasticsearch-py equivalent to alias actions?
I am trying to implement multiples indices approach using elasticsearch-dsl. There are basically two steps:
1. Create aliases:
2. Change alias when necessary:
I could only implement the step 1 using elasticsearch-py (not the dsl):
I have no clue how to do that for step 2. So, what would be the equivalent in elasticsearch-dsl (or at least in elasticsearch-py)?
python - Elasticsearch-dsl sort, find last X entries
I'm trying to find the last 30 entries into my index/doc type
I've tried nothing and I'm all out of ideas!
My current approach I find all the results over the last 5 minutes, then filter through the results and grab out the last 30 entries, but this is slower than the correct approach.
And I've tried
python - 在 elasticsearch 中删除陈旧文档的最佳实践
我有一个将模型推送到弹性搜索的 django 应用程序。保存后我有一个要更新的发布信号,但想编写一个更新所有文档的批处理命令。
在此过程中,我想删除过时的文档(例如,在数据库中设置为非活动、被删除等)。
我从这样的事情开始:
- 更新所有文档并存储更新/创建的 ID。
- 创建一个巨大的排除查询
- 删除所有匹配的文档
像这样的东西:
但是查询变得很长并且失败了。
我想知道是否有更有效的方法来做到这一点。
我在 elasticsearch.py 上使用 elasticsearch-dsl。Django-Haystack 不是一个选项。
python - 使用 elasticsearch dsl 执行嵌套搜索
嗨,我想使用 elasticsearch dsl 执行嵌套搜索,其中文档字段中包含嵌套的 json 数据,因此我希望从中获取特定的嵌套键值,例如-
以下是文件:-
我只想要存储在数组中的字段值。
fields_want = ['name', 'Marks']
输出应该是 -> {"name":"Mayank", "Marks":"80"}
Elasticsearch dsl 文档对我来说很难理解。 https://elasticsearch-dsl.readthedocs.io/en/latest/search_dsl.html#
DSL代码:-
从这段代码中,我可以在数据字段下获取整个 json 对象。
有人可以在这里指导我吗?
python - 使用信号索引模型反向 M2M
我遵循了许多示例和文档,但无法做到这一点。
每当我更新模型时,我都会尝试创建我的 Elasticsearch 索引。使用“自动索引”不会记录 M2M。
- 当我更改其中的值时,
Tag
它应该更新所有Items
is的索引
我正在使用django-elasticsearch
( here ) 这是一个包装器elasticsearch-py
。
当我尝试connect(tag_index, sender=Tag.item.through)
它时找不到标签,因为它还没有被模型导入。
这是如何正确实现的?
python - 通过 ElasticSearch DSL python 包装器创建索引时,如何在索引级别设置 ignore_malformed?
根据docs,这应该足够了:
但是我怎样才能在 python 包装器上实现这一点呢?我当前的代码如下所示:
elasticsearch-py - Elasticsearch-py Bulk Percolate 功能
试图让批量渗透功能适用于 Elasticsearch-py(即渗透),但无法在线找到示例。我可以使用 percolate 函数,所以我可以让它工作:
到目前为止,我阅读的文档似乎暗示,如果我想进行批量提交,我需要将标题和正文作为字符串发送,并用换行符分隔。因此,我尝试过:
这给了我一个通用的“elasticsearch.exceptions.TransportError”。有人有我可以适应的工作示例吗?
python - Python 脚本中不同版本的 Elasticsearch-py lib
我正在尝试从 Elasticsearch(1.7 版)获取数据,并使用带有 1 个 Python 脚本的 Elasticsearch-py 将其发布到 Elasticsearch(5.2 版)。但是官方文档(https://elasticsearch-py.readthedocs.io/en/master/)中推荐的方法是:
Elasticsearch 5.x for elasticsearch>=5.0.0,<6.0.0
Elasticsearch 1.x for elasticsearch>=1.0.0,<2.0.0
问题是我如何安装 2 个不同版本的 elasticsearch-py 并在 1 个 Python 脚本中使用它们(我正在使用 virtualenv)?
我已经检查了所有问题,例如: 使用 pip 安装多个版本的软件包 ,这里有一些建议,但是有没有更好的方法来实现这一点?
django - ElasticSearch - python 中完成建议器的批量索引
我正在尝试添加一个完成建议器,以便为我的 Django 应用程序中的搜索字段启用按输入搜索功能(使用 Elastic Search 5.2.x 和 elasticseach-dsl)。在尝试了很长时间之后,我还无法弄清楚如何对建议者进行批量索引。这是我的代码:
批量索引如下:
并在models.py中定义了一个索引方法:
根据 ES文档,建议像任何其他字段一样被编入索引。因此,我可以name_suggest =
在我的代码中的上述语句中添加一些术语,这些术语在搜索时将匹配相应的字段。但我的问题是如何处理大量记录?我猜想 ES 会有一种标准的方式来自动提出一些可以用作建议的术语。例如:使用短语中的每个单词作为术语。我可以自己想出类似的东西(通过将每个短语分解成单词),但我自己这样做似乎违反直觉,因为我猜已经有一种默认方式,用户可以在需要时进一步调整. 但是在搜索了一段时间后,在 SO/blogs/ES docs/elasticsearch-dsl docs 上找不到类似的东西。(这个Adam Wattis 的帖子对我开始很有帮助)。将不胜感激任何指针。
python - 仅在使用 python3 时实例化 Elasticsearch 客户端才会失败
我一直在尝试使用 python 的 elasticsearch 库连接到我的 ElasticSearch 主机。所以代码看起来像:
现在的问题是该指令仅在我使用 python 2.7 解释器时有效,而在 python 3.6 中它失败,产生以下错误:
Python版本:
在这两种情况下,我都使用“elasticsearch”包,版本 5.3.0
我找不到任何可以根据所使用的 python 版本提出不同行为的文档。谁能解释为什么会这样?