使用ElasticSearch索引和搜索记录。

kinto-elasticsearch的Python项目详细描述


https://img.shields.io/travis/Kinto/kinto-elasticsearch.svghttps://img.shields.io/pypi/v/kinto-elasticsearch.svghttps://coveralls.io/repos/Kinto/kinto-elasticsearch/badge.svg?branch=master

kinto elasticsearch将记录转发到elasticsearch并提供一个/search 查询索引数据的终结点。

安装

pip install kinto-elasticsearch

设置

Kinto设置中:

kinto.includes=kinto_elasticsearchkinto.elasticsearch.hosts=localhost:9200

默认情况下,ElasticSearch是智能的,索引不会在每次更改时刷新。 您可以强制执行此操作(在性能上有一定的缺陷):

kinto.elasticsearch.force_refresh=true

默认情况下,索引名称的前缀是kinto-。您可以使用:

kinto.elasticsearch.index_prefix=myprefix

运行elasticsearch

用docker在localhost:9200上运行elasticsearch的本地安装非常简单:

sudo docker run -p 9200:9200 elasticsearch

它也可以手动安装在ubuntu上:

sudo apt-get install elasticsearch

更多信息请参见official docs

用法

创建新记录:

$ echo '{"data": {"note": "kinto"}}' | http POST http://localhost:8888/v1/buckets/example/collections/notes/records --auth token:alice-token

现在应该可以使用ElasticSearch API搜索它了。

例如,使用快速查询字符串搜索:

$ http "http://localhost:8888/v1/buckets/example/collections/notes/search?q=note:kinto"--auth token:alice-token

或使用请求正文进行高级搜索:

$ echo '{"query": {"match_all": {}}}' | http POST http://localhost:8888/v1/buckets/example/collections/notes/search --auth token:alice-token
HTTP/1.1200OKAccess-Control-Expose-Headers:Retry-After, Content-Length, Alert, BackoffContent-Length:333Content-Type:application/json; charset=UTF-8Date:Wed, 20 Jan 2016 12:02:05 GMTServer:waitress{"_shards":{"failed":0,"successful":5,"total":5},"hits":{"hits":[{"_id":"453ff779-e967-4b08-99b9-5c16af865a67","_index":"example-assets","_score":1.0,"_source":{"id":"453ff779-e967-4b08-99b9-5c16af865a67","last_modified":1453291301729,"note":"kinto"},"_type":"example-assets"}],"max_score":1.0,"total":1},"timed_out":false,"took":20}

自定义索引映射

默认情况下,elasticsearch从索引记录推断数据类型。

但是可以从集合元数据定义索引映射(即模式)。 在index:schema属性中:

$ echo'{
  "data": {
    "index:schema": {
      "properties": {
        "id": {"type": "keyword"},
        "last_modified": {"type": "long"},
        "build": {
          "properties": {
              "date": {"type": "date", "format": "strict_date"},
              "id": {"type": "keyword"}
          }
        }
      }
    }
  }
}'| http PATCH "http://localhost:8888/v1/buckets/blog/collections/builds" --auth token:admin-token --verbose

有关映射的更多信息,请参阅ElasticSearch官方文档。

另请参见domapping一个用于将json模式转换为elasticsearch映射的cli工具。

运行测试

$ make tests

更改日志

0.3.1(2018-04-11)

错误修复

  • 修复reindex get_paginated_records函数。(修复61)

0.3.0(2017-09-12)

新功能

  • 添加statsd计时器以测量e/s指数化(修复54)
  • 添加一个^ {TT5}$命令重新索引现有的记录集合(修复56)

0.2.1(2017-06-14)

错误修复

  • 在查询中指定时修复结果数(ref 45)

0.2.0(2017-06-13)

错误修复

  • 限制默认返回的结果数(修复程序45)
  • 修复搜索分析异常时的崩溃(修复44)

0.1.0(2017-05-26)

新功能

  • 刷新服务器时刷新索引(修复了4)
  • 批量执行插入和删除以提高效率(修复5)
  • 添加更改时强制索引刷新的设置(修复6)
  • 添加心跳(修复3)
  • 删除存储桶和集合时删除索引(修复21)
  • 支持从querystring快速搜索(修复程序34)
  • 返回有关请求正文中无效查询的详细信息(修复程序23)
  • 支持从集合元数据中的index:schema属性定义映射(ref 8)

错误修复

  • 只有在提交了存储事务时才索引记录(修复了15)
  • 如果集合或存储桶没有读取权限,则不允许搜索(修复了7)
  • 修复在集合创建后启用插件时的空结果响应(ref 20)

内部更改

  • 创建集合时创建索引(修复27)

0.0.1(2017-05-22)

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

推荐PyPI第三方库


热门话题
带truezip的java拆分zip   java Spring,AppEngine:在AppEngine的数据源中添加postgresql url   java Android coverflow   java以编程方式创建复合过滤器,以在log4j 2中定义多个过滤器   java jpa eclipselink异常[eclipselink 4002]   中的java WordNet数据库目录相对路径。罐子   java无法在Spring Boot 2/3中显示登录的用户   java Onetomany:未找到联接表错误   java数据模型演化   java方法在类型列表中添加的(对象)不适用于参数(int)意味着什么?   用java打印两个数组   java SNMP4J发送从不超时   java添加/删除联系人(EditText)+类别(SpinnerBox),可以根据需要动态添加/删除多个联系人   语句和PreparedStatement之间的java差异   java在运行作为JAR归档文件分发的项目时加载图像等资源   来自应用程序或外部服务器的java Cron作业   多线程Java并发:并发添加和清除列表项   java更改单元测试的私有方法行为