当前位置: 首页>>代码示例>>Python>>正文


Python IndicesClient.put_mapping方法代码示例

本文整理汇总了Python中elasticsearch.client.IndicesClient.put_mapping方法的典型用法代码示例。如果您正苦于以下问题:Python IndicesClient.put_mapping方法的具体用法?Python IndicesClient.put_mapping怎么用?Python IndicesClient.put_mapping使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在elasticsearch.client.IndicesClient的用法示例。


在下文中一共展示了IndicesClient.put_mapping方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __mapFile

# 需要导入模块: from elasticsearch.client import IndicesClient [as 别名]
# 或者: from elasticsearch.client.IndicesClient import put_mapping [as 别名]
    def __mapFile(self, json_map_file):
        es = Elasticsearch([{'host': self.elasticsearch_host, 'port': self.elasticsearch_port}])
#        es = Elasticsearch([{'host': 'localhost', 'port': 9200}])
        ic = IndicesClient(es)
        with open(json_map_file) as json_data:
            d = json.load(json_data)
            doc_type = list(d.keys())[0]
            ic.put_mapping(index='wow', doc_type=doc_type, body=d)
开发者ID:wendelfleming,项目名称:USC-LunchNLearn-ElasticSearch,代码行数:10,代码来源:indexer.py

示例2: initialize

# 需要导入模块: from elasticsearch.client import IndicesClient [as 别名]
# 或者: from elasticsearch.client.IndicesClient import put_mapping [as 别名]
 def initialize(self, idx):
     es_index, es_doctype = self.indexinfo(idx)
     self.logger.info("Initializing %s" % es_index)
     idx_client = IndicesClient(self.es)
     if idx_client.exists(es_index):
         idx_client.delete(es_index)
     idx_client.create(es_index)
     if idx == 'event':
         idx_client.put_mapping(doc_type=es_doctype, index=[es_index], body=event_mapping())
     self.logger.info("%s ready." % es_index)
开发者ID:haleystorm,项目名称:nets-pipeline,代码行数:12,代码来源:ncli.py

示例3: recreate_index

# 需要导入模块: from elasticsearch.client import IndicesClient [as 别名]
# 或者: from elasticsearch.client.IndicesClient import put_mapping [as 别名]
 def recreate_index(self):
     indices_client = IndicesClient(client=settings.ES_CLIENT)
     index_name = Student._meta.es_index_name
     if indices_client.exists(index_name):
         indices_client.delete(index=index_name)
     indices_client.create(index=index_name)
     indices_client.put_mapping(
         doc_type=Student._meta.es_type_name,
         body=Student._meta.es_mapping,
         index=index_name
     )
开发者ID:bugman80,项目名称:djelastic,代码行数:13,代码来源:push-to-index.py

示例4: main

# 需要导入模块: from elasticsearch.client import IndicesClient [as 别名]
# 或者: from elasticsearch.client.IndicesClient import put_mapping [as 别名]
def main():
    # Define the globals
    global index_names
    global STARTED_TIMESTAMP
    global es
    global es_indices
    try:
        # Initiate the elasticsearch session using ES low-level client.
        # By default nodes are randomized before passed into the pool and round-robin strategy is used for load balancing.
        es = Elasticsearch(ES_HOSTS, timeout=30)
        es_indices = IndicesClient(es)

    except:
        print("Could not connect to elasticsearch!")
        sys.exit(1)

    print("Creating indices.. \n"),
    indices = generate_indices()
    print("Done!\n")

    # Register specific mapping definition for a specific type.
    print("Put Mapping \n"),
    es_indices.put_mapping(doc_type="_default_", body=mappings_body["_default_"], index="_all" )
    for type_name in types:
        es_indices.put_mapping(doc_type=type_name, body=mappings_body[type_name], index="_all" )
    print("Done!\n")

    # Retrieve mapping definition of index or index/type.
    print("GET Mapping \n"),
    print json.dumps(es_indices.get_mapping(index=["metrics_0", "metrics_1"],
                     doc_type=types),
                     sort_keys=True,
                     indent=4,
                     separators=(',', ': '))
    #print json.dumps(es_indices.get_settings(index="_all"), sort_keys=True,indent=4, separators=(',', ': '))
    print("Done!\n")

    # We will Clean up the indices by default
    # Default: True
    if CLEANUP:
        print("Cleaning up created indices.. "),
        cleanup_indices()
        print("Done!\n")
开发者ID:zhaohangbo,项目名称:Time-Series-DBs-Benchmarks,代码行数:45,代码来源:put-mapping-test.py

示例5: create_stations_mapping

# 需要导入模块: from elasticsearch.client import IndicesClient [as 别名]
# 或者: from elasticsearch.client.IndicesClient import put_mapping [as 别名]
def create_stations_mapping():
    idx_client = IndicesClient(es)

    mapping = {
        "properties": {
            "name": {
                "type": "text"
            },
            "link": {
                "type": "text"
            },
            "elevation": {
                "type": "float"
            },
            "coordinates": {
                "type": "geo_point"
            }
        }
    }

    idx_client.put_mapping(doc_type=stations_mapping, index=[stations_index], body=mapping)
开发者ID:teanocrata,项目名称:OpenSmartCountry,代码行数:23,代码来源:stations.py

示例6: _init_mapping

# 需要导入模块: from elasticsearch.client import IndicesClient [as 别名]
# 或者: from elasticsearch.client.IndicesClient import put_mapping [as 别名]
    def _init_mapping(self, mapping_path):
        esi = IndicesClient(es.get_es_handle())
        index = settings.ES_INDEX

        #first create index if not exists
        if not esi.exists(index):
            self.stdout.write("Creating index for db : %s"%index)
            esi.create(index=index)
            self.stdout.write("Index Created for : %s"%index)


        if not mapping_path or not os.path.exists(mapping_path):
            raise CommandError("not existing mapping path")

        mapping_str = open(mapping_path, "r").read()
        mappings = json.loads(mapping_str)


        for k,v in mappings.iteritems():
            res = esi.put_mapping(index, k, {k:mappings[k]})
            self.stdout.write(str(res))
开发者ID:beforebeta,项目名称:dealfu,代码行数:23,代码来源:esmanage.py

示例7: RedisEsSetupMixin

# 需要导入模块: from elasticsearch.client import IndicesClient [as 别名]
# 或者: from elasticsearch.client.IndicesClient import put_mapping [as 别名]
class RedisEsSetupMixin(object):

    def setUp(self):
        self.settings = TEST_SETTINGS_OBJECT
        self.es = get_es(self.settings)
        self.esi = IndicesClient(self.es)

        self.index = self.settings.get("ES_INDEX")

        #create the index firstly
        if self.esi.exists(self.index):
            self.esi.delete(index=self.index)

        self.esi.create(index=self.index)

        mapping_path = os.path.join(SCRAPY_ROOT,
                                 "resources/mappings.json")

        mapping_str = open(mapping_path, "r").read()
        mappings = json.loads(mapping_str)


        for k,v in mappings.iteritems():
            res = self.esi.put_mapping(self.index, k, {k:mappings[k]})
            #print res


        self.redis_conn = get_redis(self.settings)


    def tearDown(self):
        if self.esi.exists(self.index):
            self.esi.delete(index=self.index)
            print "ES INDEX DELETED"

        #remove redis stuff
        self.redis_conn.flushdb()
        print "REDIS DB DELETED"
开发者ID:beforebeta,项目名称:dealfu,代码行数:40,代码来源:test_geo.py

示例8: handle

# 需要导入模块: from elasticsearch.client import IndicesClient [as 别名]
# 或者: from elasticsearch.client.IndicesClient import put_mapping [as 别名]
    def handle(self, *args, **options):
        Student.objects.all().delete()
        University.objects.all().delete()
        Course.objects.all().delete()
        start = time.time()

        # database part
        # make some Universities
        university_names = (
            'MIT', 'MGU', 'CalTech', 'KPI', 'DPI', 'PSTU'
        )
        universities = []
        for name in university_names:
            uni = mommy.make(University, name=name)
            universities.append(uni)
        # make some courses
        template_options = ['CS%s0%s', 'MATH%s0%s', 'CHEM%s0%s', 'PHYS%s0%s']
        courses = []
        for num in range(1, 4):
            for course_num in range(1, 4):
                for template in template_options:
                    name = template % (course_num, num)
                    course = mommy.make(Course, name=name)
                    courses.append(course)

        students = []
        for _ in xrange(options.get('count')[0]):
            stud = mommy.prepare(
                Student,
                university=random.choice(universities),
                first_name=names.get_first_name(),
                last_name=names.get_last_name(),
                age=random.randint(17, 25)
            )
            students.append(stud)
        Student.objects.bulk_create(students)

        ThroughModel = Student.courses.through
        stud_courses = []
        for student_id in Student.objects.values_list('pk', flat=True):
            courses_already_linked = []
            for _ in range(random.randint(1, 10)):
                index = random.randint(0, len(courses) - 1)
                if index not in courses_already_linked:
                    courses_already_linked.append(index)
                else:
                    continue
                stud_courses.append(
                    ThroughModel(
                        student_id=student_id,
                        course_id=courses[index].pk
                    )
                )
        ThroughModel.objects.bulk_create(stud_courses)

        # recreate index
        indices_client = IndicesClient(client=settings.ES_CLIENT)
        if indices_client.exists('django'):
            indices_client.delete(index='django')
        indices_client.create(index='django')
        indices_client.put_mapping(
            doc_type='student',
            body=Student._meta.es_mapping,
            index='django'
        )
        # update part
        put_all_to_index(Student)

        finish = time.time() - start
        print '%s items  %s seconds' % (options.get('count')[0], finish)
开发者ID:7WebPages,项目名称:elastic,代码行数:72,代码来源:make_students.py

示例9: make_weather_mapping

# 需要导入模块: from elasticsearch.client import IndicesClient [as 别名]
# 或者: from elasticsearch.client.IndicesClient import put_mapping [as 别名]

#.........这里部分代码省略.........
            },
            "id": {
                "type": "long"
            },
            "main": {
                "properties": {
                    "grnd_level": {
                        "type": "float"
                    },
                    "humidity": {
                        "type": "long"
                    },
                    "pressure": {
                        "type": "long"
                    },
                    "sea_level": {
                        "type": "float"
                    },
                    "temp": {
                        "type": "float"
                    },
                    "temp_max": {
                        "type": "float"
                    },
                    "temp_min": {
                        "type": "float"
                    }
                }
            },
            "name": {
                "type": "keyword"
            },
            "rain": {
                "properties": {
                    "3h": {
                        "type": "float"
                    }
                }
            },
            "location_name": {
                "type": "keyword"
            },
            "sys": {
                "properties": {
                    "country": {
                        "type": "keyword"
                    },
                    "id": {
                        "type": "long"
                    },
                    "message": {
                        "type": "float"
                    },
                    "sunrise": {
                        "type": "date"
                    },
                    "sunset": {
                        "type": "date"
                    },
                    "type": {
                        "type": "long"
                    }
                }
            },
            "visibility": {
                "type": "long"
            },
            "weather": {
                "properties": {
                    "description": {
                        "type": "text"
                    },
                    "icon": {
                        "type": "keyword"
                    },
                    "id": {
                        "type": "long"
                    },
                    "main": {
                        "type": "keyword"
                    }
                }
            },
            "wind": {
                "properties": {
                    "deg": {
                        "type": "long"
                    },
                    "gust": {
                        "type": "float"
                    },
                    "speed": {
                        "type": "float"
                    }
                }
            }
        }
    }

    idx_client.put_mapping(doc_type=weather_mapping, index=[weather_index], body=mapping)
开发者ID:teanocrata,项目名称:OpenSmartCountry,代码行数:104,代码来源:weather.py

示例10: datetime

# 需要导入模块: from elasticsearch.client import IndicesClient [as 别名]
# 或者: from elasticsearch.client.IndicesClient import put_mapping [as 别名]
spread = 0.085
distance_in_meters = 5000

if lat_dist < spread or lon_dist < spread:
  spread = 0.015
  distance_in_meters = 1000
  minlat = minlat + (0.01)
  maxlat = maxlat - (0.01)
  minlon = minlon + (0.01)
  maxlon = maxlon - (0.01)
realtime = True

if not ic.get_mapping(index="instagram_remap",doc_type=direct):
  body = ic.get_mapping(index="instagram_remap",doc_type="baltimore")["instagram_remap"]["mappings"]["baltimore"]
  ic.put_mapping(index="instagram_remap",doc_type=direct,body=body)


start_date = datetime(int(sdate[0:4]),int(sdate[4:6]),int(sdate[6:8]),int(sdate[8:10]))
end_date = datetime(datetime.now().year,datetime.now().month,datetime.now().day,datetime.now().hour,datetime.now().minute)
if args.end_date:
  end_date = datetime(int(args.end_date[0:4]),int(args.end_date[4:6]),int(args.end_date[6:8]),int(args.end_date[8:10]))

max_secs = 460800 # 128 hours

max_images = 40 # this is the artifical max limit instagram sets...for now we'll just make it something low
min_images = 10 # increase the time window for any calls netting less than 10 images

if args.images:
  imagelogger = threading.Thread(target=logpictures)
  imagelogger.daemon = True
开发者ID:bkj,项目名称:jinsta,代码行数:32,代码来源:realtimegeo.py

示例11: IndicesClient

# 需要导入模块: from elasticsearch.client import IndicesClient [as 别名]
# 或者: from elasticsearch.client.IndicesClient import put_mapping [as 别名]
                'body': {'type': 'string'},
                'teaser': {'type': 'string'},
                'timestamp': {'type': 'date'}
                },
            '_id': {'path': 'path'}
            }
        }

    ic = IndicesClient(es)

    if not ic.exists(index):
        ic.create(index)

    if not ic.exists_type(index=index, doc_type='item'):
        ic.put_mapping(
            index=index,
            ignore_conflicts=True,
            doc_type='item',
            body=body
            )

    while 1:
        try:
            main()
        except KeyboardInterrupt:
            raise SystemExit(0)
        except:
            continue
        finally:
            sleep(0.02)
开发者ID:cutoffthetop,项目名称:recommender,代码行数:32,代码来源:isync.py

示例12: criar_indice

# 需要导入模块: from elasticsearch.client import IndicesClient [as 别名]
# 或者: from elasticsearch.client.IndicesClient import put_mapping [as 别名]

#.........这里部分代码省略.........
                "tokenizer": "standard",
                "filter": ["standard", "pt_BR", "lowercase","portuguese_stop",
                           "asciifolding"]
        }
        },
        "filter": {
            "my_stemmer": {
                "type": "stemmer",
            "name": "brazilian"
            },
             "portuguese_stop": {
                 "type":       "stop",
                 "stopwords":  "_brazilian_"
            },
             "pt_BR": {
                 "type":       "hunspell",
                 "language":  "pt_BR"
            }
        }
    }
}
}
"""
    config_mapping = """
{
  "radar" : {
    "_all" : {"enabled" : true, "analyzer": "my_analyzer"},
    "properties" : {
      "casa_legilativa_local" : {
        "type" : "string"
      },
      "casa_legislativa_esfera" : {
        "type" : "string"
      },
      "casa_legislativa_id" : {
        "type" : "long"
      },
      "casa_legislativa_nome" : {
        "type" : "string"
      },
      "casa_legislativa_nome_curto" : {
        "type" : "string"
      },
      "proposicao_ano" : {
        "type" : "string"
      },
      "proposicao_data_apresentacao" : {
        "type" : "date",
        "format" : "dateOptionalTime"
      },
      "proposicao_descricao" : {
        "type" : "string"
      },
      "proposicao_ementa" : {
        "type" : "string",
        "analyzer": "my_analyzer"
      },
      "proposicao_id" : {
        "type" : "long"
      },
      "proposicao_id_prop" : {
        "type" : "string"
      },
      "proposicao_indexacao" : {
        "type" : "string",
        "analyzer": "my_analyzer"
      },
      "proposicao_numero" : {
        "type" : "string"
      },
      "proposicao_sigla" : {
        "type" : "string"
      },
      "proposicao_situacao" : {
        "type" : "string"
      },
      "votacao_data" : {
        "type" : "date",
        "format" : "dateOptionalTime"
      },
      "votacao_descricao" : {
        "type" : "string",
        "analyzer": "my_analyzer"
      },
      "votacao_id" : {
        "type" : "long"
      },
      "votacao_id_vot" : {
        "type" : "string"
      },
      "votacao_resultado" : {
        "type" : "string"
      }
}}}
"""
    es = conectar_em_elastic_search()
    client_indice = IndicesClient(es)
    client_indice.create(index=nome_indice, body=config_settings)
    client_indice.put_mapping(
        index=nome_indice, doc_type="radar", body=config_mapping)
开发者ID:MES-1-2016,项目名称:radar,代码行数:104,代码来源:importador_elasticsearch.py


注:本文中的elasticsearch.client.IndicesClient.put_mapping方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。