本文整理汇总了Python中elastic_controller.ElasticSearchController.index_document方法的典型用法代码示例。如果您正苦于以下问题:Python ElasticSearchController.index_document方法的具体用法?Python ElasticSearchController.index_document怎么用?Python ElasticSearchController.index_document使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类elastic_controller.ElasticSearchController
的用法示例。
在下文中一共展示了ElasticSearchController.index_document方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: store_request_in_elastic_search
# 需要导入模块: from elastic_controller import ElasticSearchController [as 别名]
# 或者: from elastic_controller.ElasticSearchController import index_document [as 别名]
def store_request_in_elastic_search(property_data, search_query, request_type, adv_search_query=None):
request_id = "REQ-" + cstr(int(time.time())) + '-' + cstr(random.randint(100000,999999))
request_dict = {
"user_id":property_data.get("user_id"),
"request_id":request_id,
"operation":property_data.get("operation"),
"property_type":property_data.get("property_type"),
"property_subtype":property_data.get("property_subtype"),
"project_type":property_data.get("project_type"),
"project_subtype":property_data.get("project_subtype"),
"location":property_data.get("location"),
"property_subtype_option":property_data.get("property_subtype_option"),
"min_area":property_data.get("min_area"),
"max_area":property_data.get("max_area"),
"min_budget":property_data.get("min_budget"),
"max_budget":property_data.get("max_budget"),
"city":property_data.get("city"),
"unit_of_area":property_data.get("unit_of_area"),
"search_query":cstr(search_query),
"adv_search_query":cstr(adv_search_query),
"request_type":request_type
}
meta_dict = add_meta_fields_before_posting(property_data)
request_dict.update(meta_dict)
es = ElasticSearchController()
es_result = es.index_document("request",request_dict, request_id)
return request_id
示例2: post_property
# 需要导入模块: from elastic_controller import ElasticSearchController [as 别名]
# 或者: from elastic_controller.ElasticSearchController import index_document [as 别名]
def post_property(data):
try:
request_data = json.loads(data)
property_data, email, subs_doc = validate_data_before_property_posting(request_data)
custom_id = process_property_data_before_posting(property_data, request_data, email)
es = ElasticSearchController()
response_data = es.index_document("property",property_data, custom_id)
subscription = get_subscription_of_user(subs_doc, response_data, email)
response_msg = "Property posted successfully" if response_data.get("created",False) else "Property posting failed"
return {
"operation":"Create",
"message":response_msg,
"property_id":response_data.get("_id"),
"user_id":request_data.get("user_id"),
"data":{"subscriptions":subscription}
}
except elasticsearch.RequestError,e:
raise ElasticInvalidInputFormatError(e.error)
示例3: post_project
# 需要导入模块: from elastic_controller import ElasticSearchController [as 别名]
# 或者: from elastic_controller.ElasticSearchController import index_document [as 别名]
def post_project(data):
try:
request_data = json.loads(data) if isinstance(data,unicode) else data
user_email = putil.validate_for_user_id_exists(request_data.get("user_id"))
user_data = frappe.db.get_value("User",{"email":user_email}, "user_type", as_dict=True)
if user_data.get("user_type") == "System User":
project_data = putil.validate_property_posting_data(request_data,"property_json/project_post_mapper.json")
property_details = putil.validate_project_posting_data(project_data.get("property_details"),"property_json/project_child_table.json")
project_data["property_details"] = property_details
project_id= init_for_project_posting(project_data, user_email, request_data.get("user_id"))
init_for_project_photo_upload(request_data, project_data)
response_dict= {"operation":"Create", "user_id":request_data.get("user_id")}
es = ElasticSearchController()
response_data = es.index_document("project", project_data, project_data["project_id"])
try:
init_for_property_posting(project_data)
response_dict["message"] = "Project Posted Successfully"
except Exception,e:
response_dict["message"] ="Project Posted Successfully but Property Posting Failed"
response_dict["project_id"] = project_id
return response_dict
else:
示例4: post_property
# 需要导入模块: from elastic_controller import ElasticSearchController [as 别名]
# 或者: from elastic_controller.ElasticSearchController import index_document [as 别名]
def post_property(data):
if data:
try:
old_data = json.loads(data)
email = putil.validate_for_user_id_exists(old_data.get("user_id"))
subs_doc = putil.validate_for_postings_available(email)
data = putil.validate_property_posting_data(old_data,"property_json/property_mapper.json")
putil.validate_property_status(data.get("status"))
custom_id = "PROP-" + cstr(int(time.time())) + '-' + cstr(random.randint(10000,99999))
data["property_id"] = custom_id
meta_dict = add_meta_fields_before_posting(old_data)
data.update(meta_dict)
# return store_property_photos_in_propshikari(old_data.get("property_photos"),custom_id)
property_photo_url_dict = store_property_photos_in_propshikari(old_data.get("property_photos"),custom_id)
data["full_size_images"] = property_photo_url_dict.get("full_size",[])
data["thumbnails"] = property_photo_url_dict.get("thumbnails",[])
data["property_photo"] = property_photo_url_dict.get("thumbnails")[0] if len(property_photo_url_dict.get("thumbnails")) else ""
data["posted_by"] = old_data.get("user_id")
data["user_email"] = email
data["posting_date"] = data.get("posting_date") if data.get("posting_date") else data["creation_date"]
data["amenities"] = putil.prepare_amenities_data(data.get("amenities",""), data.get("property_type"))
data["flat_facilities"] = putil.prepare_flat_facilities_data(data.get("flat_facilities",""), data.get("property_type"))
data["possession_status"] = "Immediate" if data.get("possession") else data.get("possession_date")
data.pop("possession_date", None)
es = ElasticSearchController()
response_data = es.index_document("property",data, custom_id)
if subs_doc and response_data.get("created"):
subs_doc.posted = cint(subs_doc.posted) + 1
subs_doc.save(ignore_permissions=True)
subscription = putil.get_subscriptions(email)
response_msg = "Property posted successfully" if response_data.get("created",False) else "Property posting failed"
return {"operation":"Create", "message":response_msg, "property_id":response_data.get("_id"), "user_id":old_data.get("user_id"),"data":{"subscriptions":subscription}}
except elasticsearch.RequestError,e:
raise ElasticInvalidInputFormatError(e.error)
except elasticsearch.ElasticsearchException,e:
raise ElasticSearchException(e.error)