環(huán)境:
python3.5
支持包:
pymysql
elasticsearch_dsl
安裝 elasticsearch_dsl
pip install elasticsearch_dsl
在elasticsearch中建立一個索引及type
(索引類似于:關(guān)系數(shù)據(jù)庫中的數(shù)據(jù)庫;type類似于:關(guān)系數(shù)據(jù)庫中的表table)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2018/4/18 下午9:06
# @Author : lee
# @File : es_types.py
# @Version : 1.0
# 說明: 在elasticsearch中建立一個索引及type
from datetime import datetime
from elasticsearch_dsl import DocType, Date, Keyword, Text, Integer
# 配置hosts ip
from elasticsearch_dsl.connections import connections
connections.create_connection(hosts=["localhost"])
class ZukerType(DocType):
# 房屋的數(shù)據(jù)
"""
'title' :'名稱',
'price':'價格',
'create_date':'時間',
'desc':'介紹',
'area':'位置',
'longitude':'經(jīng)度',
'latitude':'維度',
'url': 'url',
"""
# 建立 索引和doc
title = Text(analyzer="ik_max_word")
price = Integer()
create_date = Date()
desc = Text(analyzer="ik_max_word")
area = Text(analyzer="ik_max_word")
longitude = float()
latitude = float()
url = Keyword()
# 類似于django
class Meta:
index = 'zuker' # 索引名稱
doc_type = '58house_info' # type 類似數(shù)據(jù)庫中的表[table]
if __name__ == "__main__":
ZukerType.init()