Skip to content

Commit

Permalink
Merge ab4de96 into 046f371
Browse files Browse the repository at this point in the history
  • Loading branch information
akariv committed Nov 25, 2019
2 parents 046f371 + ab4de96 commit 0930b84
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 6 deletions.
13 changes: 11 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,15 @@ 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 service elasticsearch restart || systemctl status elasticsearch.service
install:
- make install
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

0 comments on commit 0930b84

Please sign in to comment.