Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ dist:
xenial

sudo:
false
true

services:
- elasticsearch
- elasticsearch

language:
python
Expand All @@ -22,6 +22,16 @@ language:
env:
global:
- TOXENV="py${PYTHON_VERSION//./}"
jobs:
- ES_VER=5.5.0
- ES_VER=7.4.2-amd64

before_install:
- >
curl -O https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-${ES_VER}.deb &&
sudo dpkg -i --force-confnew elasticsearch-${ES_VER}.deb
- sudo -i service elasticsearch start
- sleep 20 && curl localhost:9200

install:
- make install
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ storage.create('bucket', [(doc_type, descriptor)],
reindex=False,
always_recreate=False,
mapping_generator_cls=None)
# doc_type can be None in case mapping_types are not supported (ES version >= 7.0.0)
# reindex will copy existing documents from an existing index with the same name (in case of a mapping conflict)
# always_recreate will always recreate an index, even if it already exists. default is to update mappings only.
# mapping_generator_cls allows customization of the generated mapping
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def read(*paths):
NAME = PACKAGE.replace('_', '-')
INSTALL_REQUIRES = [
'six>=1.9',
'elasticsearch>=5.0,<6.0',
'elasticsearch>=7.0,<8.0',
]
TESTS_REQUIRE = [
'mock',
Expand Down
2 changes: 1 addition & 1 deletion tableschema_elasticsearch/VERSION
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
1.0.0
1.1.0

22 changes: 20 additions & 2 deletions tableschema_elasticsearch/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class Storage(object):
def __init__(self, es=None):
# Use the passed `es` or create a new Elasticsearch instance
self.__es = es if es is not None else Elasticsearch()
self.__no_mapping_types = self.__es.info()['version']['number'] >= '7'

def __repr__(self):
# Template and format
Expand Down Expand Up @@ -74,7 +75,11 @@ def put_mapping(self, bucket, doc_types, index_name, mapping_generator_cls):
mapping = mappers.descriptor_to_mapping(
descriptor, mapping_generator_cls=mapping_generator_cls
)
self.__es.indices.put_mapping(doc_type, mapping, index=index_name)
params = dict()
if doc_type is not None and self.__no_mapping_types:
params = dict(include_type_name='true')
self.__es.indices.put_mapping(mapping, doc_type=doc_type,
index=index_name, params=params)

def generate_doc_id(self, row, primary_key):
return '/'.join([str(row.get(k)) for k in primary_key])
Expand Down Expand Up @@ -164,8 +169,21 @@ def iter(self, bucket, doc_type=None):
size = 100
done = False
while not done:
body = None
if doc_type is not None:
body = dict(
query=dict(
bool=dict(
filter=dict(
match=dict(
_type=doc_type
)
)
)
)
)
results = self.__es.search(index=bucket,
doc_type=doc_type,
body=body,
from_=from_,
size=size)
hits = results.get('hits', {}).get('hits', [])
Expand Down