Package: kinto-elasticsearch
kinto-elasticsearchforwards the records to ElasticSearch and provides a/searchendpoint to query the indexed data.Installpip install kinto-elasticsearchSetupIn theKintosettings:kinto.includes=kinto_elasticsearchkinto.elasticsearch.hosts=localhost:9200By default, ElasticSearch is smart and indices are not refreshed on every change.
You can force this (with a certain drawback in performance):kinto.elasticsearch.force_refresh=trueBy default, indices names are prefixed withkinto-. You change this with:kinto.elasticsearch.index_prefix=myprefixRun ElasticSearchRunning a local install ofElasticSearchonlocalhost:9200with Docker is pretty straightforward:sudo docker run -p 9200:9200 elasticsearchIt is also be installed manually on Ubuntu with:sudo apt-get install elasticsearchAnd more information is available in theofficial docs.UsageCreate a new record:$ echo '{"data": {"note": "kinto"}}' | http POST http://localhost:8888/v1/buckets/example/collections/notes/records --auth token:alice-tokenIt should now be possible to search for it using theElasticSearch API.For example, using a quick querystring search:$ http "http://localhost:8888/v1/buckets/example/collections/notes/search?q=note:kinto"--auth token:alice-tokenOr an advanced search using request body:$ echo '{"query": {"match_all": {}}}' | http POST http://localhost:8888/v1/buckets/example/collections/notes/search --auth token:alice-tokenHTTP/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}Custom index mappingBy default, ElasticSearch infers the data types from the indexed records.But it’s possible to define the index mappings (ie. schema) from the collection metadata,
in theindex:schemaproperty:$echo'{
  "data": {
    "index:schema": {
      "properties": {
        "id": {"type": "keyword"},
        "last_modified": {"type": "long"},
        "build": {
          "properties": {
              "date": {"type": "date", "format": "strict_date"},
              "id": {"type": "keyword"}
          }
        }
      }
    }
  }
}'|httpPATCH"http://localhost:8888/v1/buckets/blog/collections/builds"--authtoken:admin-token--verboseRefer to ElasticSearch official documentation for more information about mappings.See also,domappinga CLI tool to convert JSON schemas to ElasticSearch mappings.Running the tests$ make testsChangelog0.3.1 (2018-04-11)Bug fixesFix the reindex get_paginated_records function. (fixes #61)0.3.0 (2017-09-12)New featuresAdd StatsD timer to measure E/S indexation (fixes #54)Add akinto-reindexcommand to reindex existing collections of records (fixes #56)0.2.1 (2017-06-14)Bug fixesFix the number of results when specified in query (ref #45)0.2.0 (2017-06-13)Bug fixesLimit the number of results returned by default (fixes #45)Fix crash on search parse exceptions (fixes #44)0.1.0 (2017-05-26)New featuresFlush indices when server is flushed (fixes #4)Perform insertions and deletion in bulk for better efficiency (fixes #5)Add setting to force index refresh on change (fixes #6)Add heartbeat (fixes #3)Delete indices when buckets and collections are deleted (fixes #21)Support quick search from querystring (fixes #34)Return details about invalid queries in request body (fixes #23)Support defining mapping from theindex:schemaproperty in the collection metadata (ref #8)Bug fixesOnly index records if the storage transaction is committed (fixes #15)Do not allow to search if no read permission on collection or bucket (fixes #7)Fix empty results response when plugin was enabled after collection creation (ref #20)Internal changesCreate index when collection is created (fixes #27)0.0.1 (2017-05-22)Import code fromKinto official tutorial