跳转到主要内容

使用ElasticSearch索引和搜索记录。

项目描述

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

kinto-elasticsearch 将记录转发到ElasticSearch,并提供一个 /search 端点以查询索引数据。

安装

pip install kinto-elasticsearch

设置

Kinto 设置中

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

默认情况下,ElasticSearch非常智能,不会在每次更改时刷新索引。您可以强制刷新(但会降低性能)

kinto.elasticsearch.force_refresh = true

默认情况下,索引名称以 kinto- 前缀。您可以通过以下方式更改它

kinto.elasticsearch.index_prefix = myprefix

运行ElasticSearch

使用Docker在本地安装 ElasticSearchlocalhost:9200 非常简单

sudo docker run -p 9200:9200 elasticsearch

也可以在Ubuntu上手动安装

sudo apt-get install elasticsearch

更多信息请参阅 官方文档

使用方法

创建一个新记录

$ 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.1 200 OK
Access-Control-Expose-Headers: Retry-After, Content-Length, Alert, Backoff
Content-Length: 333
Content-Type: application/json; charset=UTF-8
Date: Wed, 20 Jan 2016 12:02:05 GMT
Server: 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映射的命令行工具。

运行测试

$ make tests

变更日志

0.3.1 (2018-04-11)

错误修复

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

0.3.0 (2017-09-12)

新功能

  • 添加StatsD计时器来衡量E/S索引化(修复#54)

  • 添加 kinto-reindex 命令以重新索引现有记录集合(修复#56)

0.2.1 (2017-06-14)

错误修复

  • 修复指定查询时结果的数量(参考#45)

0.2.0 (2017-06-13)

错误修复

  • 默认限制返回结果的数量(修复#45)

  • 修复搜索解析异常时的崩溃(修复#44)

0.1.0 (2017-05-26)

新功能

  • 当服务器刷新时刷新索引(修复#4)

  • 批量进行插入和删除以提高效率(修复#5)

  • 添加设置以强制在更改时刷新索引(修复#6)

  • 添加心跳(修复#3)

  • 当删除存储桶和集合时删除索引(修复#21)

  • 支持从查询字符串进行快速搜索(修复#34)

  • 在请求体中返回有关无效查询的详细信息(修复#23)

  • 支持从集合元数据中的 index:schema 属性定义映射(参考#8)

错误修复

  • 只有当存储事务提交时才索引记录(修复#15)

  • 不允许在没有集合或存储桶的读取权限的情况下进行搜索(修复#7)

  • 修复在集合创建后启用插件时的空结果响应(参考#20)

内部更改

  • 创建索引时创建索引(修复#27)

0.0.1 (2017-05-22)

项目详情


下载文件

下载您平台的文件。如果您不确定要选择哪个,请了解更多关于 安装软件包 的信息。

源分布

kinto-elasticsearch-0.3.1.tar.gz (14.1 kB 查看哈希值)

上传时间 源代码

构建分发版

kinto_elasticsearch-0.3.1-py2.py3-none-any.whl (12.9 kB 查看哈希值)

上传时间 Python 2 Python 3