from es_operate import ESCURD from elasticsearch import Elasticsearch import os import sys sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) import create_connection import configparser dir_name = os.path.abspath(os.path.dirname(__file__)) es_config = configparser.ConfigParser() es_config.read(os.path.join(dir_name, "es.ini")) es_server_ip_port = es_config["ServerAddress"]["es_server_ip_port"] # 使用配置文件中的index_name,也可以自己命名,创建其他名称的索引 index_name = es_config["ServerInfo"]["index_name_1"] http_auth_user_name = es_config["ServerAddress"]["http_auth_user_name"] http_auth_password = es_config["ServerAddress"]["http_auth_password"] es_connect = Elasticsearch(es_server_ip_port, http_auth=(http_auth_user_name, http_auth_password)) es_faq = ESCURD(es_connect) if __name__ == "__main__": owner_names = ["领域1,领域2,领域3"] for owner_name in owner_names: es_faq.del_data(index_name, owner_name)
es_server_ip_port = es_config["ServerAddress"]["es_server_ip_port"] index_name = es_config["ServerInfo"]["alias_name"] if_es_use_passwd = es_config["ServerAddress"]["if_es_use_passwd"] if if_es_use_passwd == "1": http_auth_user_name = es_config["ServerAddress"]["http_auth_user_name"] http_auth_password = es_config["ServerAddress"]["http_auth_password"] es_connect = Elasticsearch(es_server_ip_port, http_auth=(http_auth_user_name, http_auth_password)) else: es_connect = Elasticsearch(es_server_ip_port) es_faq = ESCURD(es_connect) class SearchData(object): # 实现搜索框的中文提示词的类 def search_question_cn(self, owner_name, current_question, limit_num, if_middle): current_question = current_question.lower() search_limit_num = 100 retrieve_data = es_faq.search_cn(index_name, owner_name, current_question, search_limit_num, if_middle) retrieve_results = retrieve_data["hits"] max_result_len = retrieve_results["total"]["value"]
es_config = configparser.ConfigParser() es_config.read(os.path.join(dir_name, "es.ini")) es_server_ip_port = es_config["ServerAddress"]["es_server_ip_port"] alias_name = es_config["ServerInfo"]["alias_name"] index_name_1 = es_config["ServerInfo"]["index_name_1"] index_name_2 = es_config["ServerInfo"]["index_name_2"] index_name_set = set([index_name_1, index_name_2]) http_auth_user_name = es_config["ServerAddress"]["http_auth_user_name"] http_auth_password = es_config["ServerAddress"]["http_auth_password"] es_connect = Elasticsearch(es_server_ip_port, http_auth=(http_auth_user_name, http_auth_password)) es_faq = ESCURD(es_connect) stopwords4BEFAQ = StopwordsBEFAQ() class ReadsSqlData2ES(object): def __init__(self): self.exceldata = ExcelData() self.excel_list = self.exceldata.read_QA_data() def write_data2es(self, index_name): ''' @Author: xiaoyichao @param {type} @Description: 将数据写到ES中 '''
LastEditors: xiaoyichao @Date: 2020-01-02 16:55:23 LastEditTime: 2020-08-12 18:41:05 @Description: ''' from es_operate import ESCURD from elasticsearch import Elasticsearch import os import configparser dir_name = os.path.abspath(os.path.dirname(__file__)) es_config = configparser.ConfigParser() es_config.read(os.path.join(dir_name, "es.ini")) es_server_ip_port = es_config["ServerAddress"]["es_server_ip_port"] # 使用配置文件中的index_name,也可以自己命名,创建其他名称的索引 index_name_1 = es_config["ServerInfo"]["index_name_1"] index_name_2 = es_config["ServerInfo"]["index_name_2"] http_auth_user_name = es_config["ServerAddress"]["http_auth_user_name"] http_auth_password = es_config["ServerAddress"]["http_auth_password"] es_connect = Elasticsearch(es_server_ip_port, http_auth=(http_auth_user_name, http_auth_password)) es_faq = ESCURD(es_connect) if __name__ == "__main__": es_faq.create_index(index_name=index_name_1) # es_faq.create_index(index_name=index_name_2)
import os import sys sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) import configparser import create_connection import json import os import sys import datetime dir_name = os.path.abspath(os.path.dirname(__file__)) es_config = configparser.ConfigParser() es_config.read(os.path.join(dir_name, "es.ini")) es_server_ip_port = es_config["ServerAddress"]["es_server_ip_port"] index_name_1 = es_config["ServerInfo"]["index_name_1"] index_name_2 = es_config["ServerInfo"]["index_name_2"] http_auth_user_name = es_config["ServerAddress"]["http_auth_user_name"] http_auth_password = es_config["ServerAddress"]["http_auth_password"] es_connect = Elasticsearch(es_server_ip_port, http_auth=(http_auth_user_name, http_auth_password)) es_faq = ESCURD(es_connect) if __name__ == "__main__": es_faq.del_index(index_name=index_name_1) es_faq.del_index(index_name=index_name_2)