Elasticsearch服务器代理设置
项目描述
本软件包提供了一种基于真实Elasticsearch服务器的Elasticsearch服务器代理设置。
README
setup
此测试使用Elasticsearch服务器。此测试的setUp方法调用我们的startElasticSearchServer方法,该方法启动一个Elasticsearch服务器。第一次调用此测试时,将下载新的Elasticsearch服务器。测试设置如下:
def test_suite(): return unittest.TestSuite(( doctest.DocFileSuite('README.txt', setUp=testing.doctestSetUp, tearDown=testing.doctestTearDown, optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS, encoding='utf-8'), ))
如果您想设置一些自定义设置,可以使用confSource,它必须指向一个包含elasticsearch.yml或elasticsearch.json以及logging.yml和可选映射定义的配置文件夹。您的自定义doctest setUp和tearDown方法可能如下所示
def mySetUp(test): # use default elasticsearch with our server and conf source dir here = os.path.dirname(__file__) serverDir = os.path.join(here, 'server') confSource = os.path.join(here, 'config') p01.elasticstub.testing.startElasticSearchServer(serverDir=serverDir, confSource=confSource) def myTearDown(test): p01.elasticstub.testing.stopElasticSearchServer() # do some custom teardown stuff here
testing
让我们设置一个python httplib连接
>>> import httplib >>> conn = httplib.HTTPConnection('localhost', 45200)
并测试集群状态
>>> conn.request('GET', '_cluster/state') >>> response = conn.getresponse() >>> response.status 200>>> import json >>> from pprint import pprint >>> body = response.read() >>> pprint(json.loads(body)) {u'blocks': {}, u'cluster_name': u'p01_elasticstub_testing', u'master_node': u'...', u'metadata': {u'cluster_uuid': u'...', u'index-graveyard': {u'...': []}, u'indices': {}, u'templates': {}}, u'nodes': {u'...': {u'attributes': {}, u'ephemeral_id': u'...', u'name': u'...', u'transport_address': u'...'}}, u'routing_nodes': {u'nodes': {u'...': []}, u'unassigned': []}, u'routing_table': {u'indices': {}}, u'state_uuid': u'...', u'version': 2}
如您所见,我们的映射为空
>>> conn.request('GET', '/testing/test/_mapping') >>> response = conn.getresponse() >>> body = response.read() >>> pprint(json.loads(body)) {u'error': {u'index': u'testing', u'index_uuid': u'_na_', u'reason': u'no such index', u'resource.id': u'testing', u'resource.type': u'index_or_alias', u'root_cause': [{u'index': u'testing', u'index_uuid': u'_na_', u'reason': u'no such index', u'resource.id': u'testing', u'resource.type': u'index_or_alias', u'type': u'index_not_found_exception'}], u'type': u'index_not_found_exception'}, u'status': 404}
让我们索引一个简单的项目
>>> body = json.dumps({u'title': u'Title'}) >>> conn.request('POST', '/testing/test/1', body) >>> response = conn.getresponse() >>> body = response.read() >>> pprint(json.loads(body)) {u'_id': u'1', u'_index': u'testing', u'_shards': {u'failed': 0, u'successful': 1, u'total': 2}, u'_type': u'test', u'_version': 1, u'created': True, u'result': u'created'}
刷新
>>> conn.request('GET', '/testing/test/_refresh') >>> response = conn.getresponse() >>> body = response.read() >>> pprint(json.loads(body)) {u'_id': u'_refresh', u'_index': u'testing', u'_type': u'test', u'found': False}
让我们设置一个映射
>>> body = json.dumps({'test': {'properties': {'title': {'type': 'string'}}}}) >>> conn.request('POST', '/testing/test/_mapping', body) >>> response = conn.getresponse() >>> body = response.read() >>> pprint(json.loads(body)) {u'acknowledged': True}
并再次测试我们的映射
>>> conn.request('GET', '/testing/test/_mapping') >>> response = conn.getresponse() >>> body = response.read() >>> pprint(json.loads(body)) {u'testing': {u'mappings': {u'test': {u'properties': {u'title': {u'fields': {u'keyword': {u'ignore_above': 256, u'type': u'keyword'}}, u'type': u'text'}}}}}}
CHANGES
0.5.4 (2017-11-02)
切换到elasticsearch 5.6.4并调整启动脚本环境设置
移除了thrift插件支持
调整默认elasticsearch配置,添加log4j配置文件
0.5.3 (2014-07-10)
切换到elasticsearch版本1.2.1。注意;版本1.2.2在至少Windows上无法工作。启动时退出并显示错误如{1.2.2}:初始化失败 … 执行错误[java.lang.IncompatibleClassChangeError:实现类] IncompatibleClassChangeError[实现类]
0.5.2 (2012-12-22)
切换到elasticsearch 0.20.1。注意;没有必要仅仅为了获取最新版本而切换到新版本。只需使用downloadURL属性设置较新版本的elasticsearch下载URL
似乎默认情况下自动映射不再工作。在插入第一个项目后添加显式映射设置。这似乎按预期工作。
错误修复:调整基本URL,如果与版本一起使用,从git切换到elasticsearch
0.5.1 (2012-12-10)
切换到elasticsearch 0.20.0
添加版本参数到startElasticSearchServer
清理导入
0.5.0 (2012-11-18)
初始版本在win 32位和posix 32位上进行了测试。尚未在win 64位、posix 64位和mac 32/64位系统上测试。
项目详情
p01.elasticstub-0.5.4.tar.gz的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | c1b05f2fee640a435677f28b05d958776fba10f3da57c7e4da490e455370024e |
|
MD5 | 8db72c8f102b0b11713ebb2d4f2d0f48 |
|
BLAKE2b-256 | 04f6a03cd2334f6c9de5a046078f7228a8da6496194fdbeae3a51c3a30945e45 |