本文整理汇总了Python中elasticsearch.client.IndicesClient.put_settings方法的典型用法代码示例。如果您正苦于以下问题:Python IndicesClient.put_settings方法的具体用法?Python IndicesClient.put_settings怎么用?Python IndicesClient.put_settings使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类elasticsearch.client.IndicesClient
的用法示例。
在下文中一共展示了IndicesClient.put_settings方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from elasticsearch.client import IndicesClient [as 别名]
# 或者: from elasticsearch.client.IndicesClient import put_settings [as 别名]
def main():
parser = argparse.ArgumentParser()
parser.add_argument("--src-host", action="store", default="127.0.0.1", type=unicode, help="Source host [default: %(default)s]")
parser.add_argument("--src-port", action="store", default=9200, help="Source port [default: %(default)s]")
parser.add_argument("--src-index", action="store", default="", type=unicode, help="Source index")
parser.add_argument("--src-batch-size", action="store", type=int, default=5000, help="Source query batchsize [default: %(default)s]")
parser.add_argument("--src-scroll-interval", action="store", type=unicode, default="60m", help="Interval for source scroll query [default: %(default)s]")
parser.add_argument("--dest-host", action="store", default="127.0.0.1", type=unicode, help="Destination host [default: %(default)s]")
parser.add_argument("--dest-port", action="store", default=9200, help="Destination port [default: %(default)s]")
parser.add_argument("--dest-index", action="store", default="", type=unicode, help="Destination index")
parser.add_argument("--dest-batch-size", action="store", type=int, default=5000, help="Destination batchsize [default: %(default)s]")
parser.add_argument("--dest-alias", action="store", help="Destination index alias (to be set after we have finished populating)")
parser.add_argument("--dest-concurrency", action="store", type=int, default=4, help="Destination batchsize [default: %(default)s]")
parser.add_argument("--dest-delete-index", action="store_true", help="Delete destination index at before starting")
parser.add_argument("--query", action="store", type=unicode, default="", help="Query to use [if None is specified, a match_all will be used]")
args = parser.parse_args()
if args.src_index is None or len(args.src_index) == 0:
raise Exception("--src-index must be specified!")
if args.dest_index is None or len(args.dest_index) == 0:
raise Exception("--dest-index must be specified!")
dt_start = datetime.now()
# copy mapping
src_es_instance = get_elasticsearch(args.src_host, args.src_port)
dest_es_instance = get_elasticsearch(args.dest_host, args.dest_port)
# check if src_index exists
src_es_ic = IndicesClient(src_es_instance)
if not src_es_ic.exists(args.src_index):
raise Exception("--src-index %s does not exist!" % args.src_index)
# check if dest_index exists
dest_es_ic = IndicesClient(dest_es_instance)
if dest_es_ic.exists(args.dest_index):
if args.dest_delete_index:
dest_es_ic.delete(index=args.dest_index)
else:
raise Exception("--dest-index %s already exists! Use --dest-delete-index if you want to drop it" % args.dest_index)
log.info("Copying mapping...")
# copy mapping over to dest
src_index_information = src_es_ic.get(index=args.src_index)
dest_es_ic.create(index=args.dest_index, body=src_index_information.get(args.src_index, {}))
# set num_of_replicas to 0
dest_es_ic.put_settings(index=args.dest_index, body={"settings": {"index": {"number_of_replicas": 0}}})
# perform multiprocessing
log.info("Copying data...")
MAGIC_STRING = "%s:%s" % (str(uuid4()), str(uuid4()))
DEST_QUEUE = Queue()
DEST_COUNTER = Value('i', 0)
src_process = Process(target=src_worker, args=(args, DEST_QUEUE, MAGIC_STRING))
src_process.start()
dest_processes = [Process(target=dest_worker, args=(args, DEST_QUEUE, MAGIC_STRING, DEST_COUNTER)) for i in xrange(args.dest_concurrency)]
for i in dest_processes: i.start()
src_process.join()
for i in dest_processes: i.join()
log.info("[dest_worker] Total processed %s" % DEST_COUNTER.value)
if args.dest_alias is not None and len(args.dest_alias) > 0:
# we remove all existing mappings to this alias, then add it to the current dest_index
for idx_name, aliases_mapping in dest_es_ic.get_aliases().iteritems():
if args.dest_alias in aliases_mapping.get("aliases", {}):
dest_es_ic.delete_alias(index=idx_name, name=args.dest_alias)
dest_es_ic.put_alias(index=args.dest_index, name=args.dest_alias)
dest_es_ic.refresh(args.dest_index)
dt_end = datetime.now()
log.info("Time elapsed: %s" % (dt_end-dt_start, ))
示例2: cancel_replica_shards
# 需要导入模块: from elasticsearch.client import IndicesClient [as 别名]
# 或者: from elasticsearch.client.IndicesClient import put_settings [as 别名]
def cancel_replica_shards(es):
indices = IndicesClient(es)
pprint(indices.put_settings({"index.number_of_replicas": 0}, "_all"))
示例3: Elasticsearch
# 需要导入模块: from elasticsearch.client import IndicesClient [as 别名]
# 或者: from elasticsearch.client.IndicesClient import put_settings [as 别名]
from elasticsearch.client import IndicesClient
from elasticsearch_dsl import Mapping, String, Search
es = Elasticsearch()
ies = IndicesClient(es)
ies.delete('test')
ies.create('test')
ies.close('test')
ies.put_settings(index='test', body={
"analysis":{
"analyzer":{
"default":{
"type":"custom",
"tokenizer":"standard",
"filter":[ "standard", "lowercase", "stop", "kstem" ]
}
}
}
})
m = Mapping('test')
m.field('f', String())
m.save(index='test', using=es)
ies.open(index='test')
es.index('test', 'test', {
示例4: create_replica_shards
# 需要导入模块: from elasticsearch.client import IndicesClient [as 别名]
# 或者: from elasticsearch.client.IndicesClient import put_settings [as 别名]
def create_replica_shards(es):
# https://www.elastic.co/guide/en/elasticsearch/reference/2.3/indices-update-settings.html
indices = IndicesClient(es)
pprint(indices.put_settings({"index.number_of_replicas": 1}, "_all"))