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