Skip to content

Commit 3a7d8b7

Browse files
akarivroll
authored andcommitted
Add support for ElasticSearch 7.0.0 and up (#14)
* v0.5.0 Bump elasticsearch dependency to +7.0 * Travis test matrix * lint * travis * Sniff server version * travis * Fix readme
1 parent 046f371 commit 3a7d8b7

File tree

5 files changed

+35
-6
lines changed

5 files changed

+35
-6
lines changed

.travis.yml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ dist:
22
xenial
33

44
sudo:
5-
false
5+
true
66

77
services:
8-
- elasticsearch
8+
- elasticsearch
99

1010
language:
1111
python
@@ -22,6 +22,16 @@ language:
2222
env:
2323
global:
2424
- TOXENV="py${PYTHON_VERSION//./}"
25+
jobs:
26+
- ES_VER=5.5.0
27+
- ES_VER=7.4.2-amd64
28+
29+
before_install:
30+
- >
31+
curl -O https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-${ES_VER}.deb &&
32+
sudo dpkg -i --force-confnew elasticsearch-${ES_VER}.deb
33+
- sudo -i service elasticsearch start
34+
- sleep 20 && curl localhost:9200
2535

2636
install:
2737
- make install

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ storage.create('bucket', [(doc_type, descriptor)],
119119
reindex=False,
120120
always_recreate=False,
121121
mapping_generator_cls=None)
122+
# doc_type can be None in case mapping_types are not supported (ES version >= 7.0.0)
122123
# reindex will copy existing documents from an existing index with the same name (in case of a mapping conflict)
123124
# always_recreate will always recreate an index, even if it already exists. default is to update mappings only.
124125
# mapping_generator_cls allows customization of the generated mapping

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def read(*paths):
2222
NAME = PACKAGE.replace('_', '-')
2323
INSTALL_REQUIRES = [
2424
'six>=1.9',
25-
'elasticsearch>=5.0,<6.0',
25+
'elasticsearch>=7.0,<8.0',
2626
]
2727
TESTS_REQUIRE = [
2828
'mock',

tableschema_elasticsearch/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
1.0.0
1+
1.1.0
22

tableschema_elasticsearch/storage.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class Storage(object):
3939
def __init__(self, es=None):
4040
# Use the passed `es` or create a new Elasticsearch instance
4141
self.__es = es if es is not None else Elasticsearch()
42+
self.__no_mapping_types = self.__es.info()['version']['number'] >= '7'
4243

4344
def __repr__(self):
4445
# Template and format
@@ -74,7 +75,11 @@ def put_mapping(self, bucket, doc_types, index_name, mapping_generator_cls):
7475
mapping = mappers.descriptor_to_mapping(
7576
descriptor, mapping_generator_cls=mapping_generator_cls
7677
)
77-
self.__es.indices.put_mapping(doc_type, mapping, index=index_name)
78+
params = dict()
79+
if doc_type is not None and self.__no_mapping_types:
80+
params = dict(include_type_name='true')
81+
self.__es.indices.put_mapping(mapping, doc_type=doc_type,
82+
index=index_name, params=params)
7883

7984
def generate_doc_id(self, row, primary_key):
8085
return '/'.join([str(row.get(k)) for k in primary_key])
@@ -164,8 +169,21 @@ def iter(self, bucket, doc_type=None):
164169
size = 100
165170
done = False
166171
while not done:
172+
body = None
173+
if doc_type is not None:
174+
body = dict(
175+
query=dict(
176+
bool=dict(
177+
filter=dict(
178+
match=dict(
179+
_type=doc_type
180+
)
181+
)
182+
)
183+
)
184+
)
167185
results = self.__es.search(index=bucket,
168-
doc_type=doc_type,
186+
body=body,
169187
from_=from_,
170188
size=size)
171189
hits = results.get('hits', {}).get('hits', [])

0 commit comments

Comments
 (0)