python-elasticsearch集成(用于aasanjobs内部使用)

ajelastic的Python项目详细描述


aasaanjobs弹性搜索sdk

用python处理elasticsearch相关事务的库(用于aasanjobs中的内部使用)

要求

  • python 3.5及更高版本
  • ElasticSearchPython

安装

使用pip

安装
pip install ajelastic

配置

aj弹性库从环境中指定的模块路径读取配置 变量AJELASTIC_SETTINGS_MODULE如果它是一个独立的python项目,或者 DJANGO_SETTINGS_MODULE如果是django项目,则为环境变量。

export AJELASTIC_SETTINGS_MODULE=tests.settings

示例

下面是库可以使用的示例设置模块

# Mandatory Settings# Elasticsearch host and portES_HOST="http://localhost:9200"# The environment suffix that will be added in the Elasticsearch index namesES_ENV="development"# Optional Settings# List of Elasticsearch indicesES_INDICES={"User":{"name":"users",# The index name prefix"doc_type":"user",# Elastic document type"data_functions":{"single":"tests.data:get_user",# Function to fetch a user; should accept a single ID argument"multi":"tests.data:list_users"# Function to fetch list of users; should accept two arguments; limit and offset},"mapping_path":"tests/user_mapping.json"# Path to the JSON mapping of the document structure}}

与ElasticSearch同步数据的命令

此库提供以下命令行脚本来同步/初始化数据

aj-es-reindex

此命令将从头开始重新编制文档索引,从data_functions.multi中定义的函数获取数据。 实体的设置(即使用ES_INDICES设置)。

对于eg,下面的命令将重新索引用户实体,从list_users函数获取数据(如设置中指定的那样) 批量大小为100,即在单个请求中,100个用户将成为ElasticSearch的索引。

aj-es-reindex User 100

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java如何使用JNA创建同一库的多个实例?   java在将Graphql查询作为JSON字符串传递时收到意外的令牌错误   OAuth2 oltu的java问题   java桌面应用程序使用的好的嵌入式数据库是什么?   java Firebase数据库高级查询选项   java正在使磁盘上的EhCache元素过期   java 安卓还原处于backstack中的片段的实例状态   XMemcached中的java异步集   java TimescaleDB是否使用与Postgresql完全相同的JDBC驱动程序?   java从网站c读取信息#   检查java Android中的字符串是否只包含数字和空格   c#如何向web服务发送特殊字符?   grails无法调用需要java的方法。lang.类参数?   java我在组合框中调用的方法不会运行所有代码,它只运行部分代码   java发送带有标头的HTTP GET请求