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


Python elastic_controller.ElasticSearchController类代码示例

本文整理汇总了Python中elastic_controller.ElasticSearchController的典型用法代码示例。如果您正苦于以下问题:Python ElasticSearchController类的具体用法?Python ElasticSearchController怎么用?Python ElasticSearchController使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: add_photo_to_property

def add_photo_to_property(data):
	request_data = json.loads(data)
	prop_dict = {"user_id":request_data.get("user_id"), "sid":request_data.get("sid"), "property_id":request_data.get("property_id"), 
					"fields":["thumbnails", "full_size_images", "property_photo"]}
	field_dict = {}
	prop_response = get_property_details(json.dumps(prop_dict))
	if request_data.get("property_photos"):
		photo_dict = store_property_photos_in_propshikari(request_data.get("property_photos"),request_data.get("property_id"))
		photo_dict.get("full_size").extend(prop_response.get("data").get("full_size_images", []))
		photo_dict.get("thumbnails").extend(prop_response.get("data").get("thumbnails", []))
		field_dict["full_size_images"] = photo_dict.get("full_size")
		field_dict["thumbnails"] = photo_dict.get("thumbnails")
		field_dict["property_photo"] = field_dict.get("thumbnails")[0] if len(field_dict.get("thumbnails")) else ""
		search_query = {"doc": field_dict }
		es = ElasticSearchController()
		update_response = es.update_docuemnt("property", request_data.get("property_id"), search_query)
		prop_response = get_property_details(json.dumps(prop_dict))
		
		return { 
					"message":"Property Photos Updated successfully",
					"full_size_images":prop_response.get("data").get("full_size_images", []),
					"thumbnails":prop_response.get("data").get("thumbnails", []),
					"property_photo":prop_response.get("data").get("property_photo", [])
				}
	else:
		raise DoesNotExistError("Images not Attached")
开发者ID:arpitjain06,项目名称:propshikhari,代码行数:26,代码来源:property_update_api.py

示例2: shortlist_property

def shortlist_property(request_data):
	if request_data:
		request_data = json.loads(request_data)
		email = putil.validate_for_user_id_exists(request_data.get("user_id"))
		if not request_data.get("property_id"):
			raise MandatoryError("Mandatory Field Property Id missing")
		property_name = frappe.db.get_value("Shortlisted Property", {"property_id":request_data.get("property_id"), "user_id":request_data.get("user_id")} ,["name","status"], as_dict=1)
		if property_name:
			if property_name.get("status") == 'Active':	
				raise DuplicateEntryError("Property {0} already Shortlisted".format(request_data.get("property_id")))
			elif property_name.get("status") == 'Inactive':
				sp_doc = frappe.get_doc("Shortlisted Property", property_name.get("name"))
				sp_doc.status = "Active"
				sp_doc.save(ignore_permissions=True)
		else:
			try:
				sp_doc = frappe.new_doc("Shortlisted Property")
				sp_doc.user_id = request_data.get("user_id")
				sp_doc.property_id = request_data.get("property_id")
				sp_doc.status = "Active"
				sp_doc.save()
				es = ElasticSearchController()
				es.refresh_index()
			except frappe.MandatoryError,e:
				raise MandatoryError("Mandatory Field {0} missing".format(e.message))
			except (frappe.LinkValidationError, frappe.ValidationError)  as e:
				raise InvalidDataError(e.message)
			except Exception,e:
				raise OperationFailed("Shortlist Property Operation Failed")
开发者ID:arpitjain06,项目名称:propshikhari,代码行数:29,代码来源:property_masters.py

示例3: get_similar_properties

def get_similar_properties(request_data):
	if request_data:
		request_data = json.loads(request_data)
		email = putil.validate_for_user_id_exists(request_data.get("user_id"))
		putil.validate_property_data(request_data, ["request_type", "id"])
		search_dict = {"property_id":get_search_query_of_property_id ,"request_id":get_search_query_of_request_id}
		if request_data.get("request_type") not in ["property_id", "request_id"]:
			raise InvalidDataError("Request type contains Invalid Data")
		search_query, uom = search_dict.get(request_data.get("request_type"))(request_data)
		try:
			
			sp_include_fields = ["property_photo", "property_id", "location", "address",
			                      "city", "carpet_area", "price","property_title"]
			es = ElasticSearchController()
			response_data, total_records = es.search_document(["property"], search_query, request_data.get("page_number",1), request_data.get("records_per_page",4), [], sp_include_fields)
			uom = "Sq.Ft." if uom not in ["Sq.Ft.", "Acres", "Hectares"] else uom
			putil.convert_area_according_to_uom(response_data, uom)
			response_msg = "Similar Property Found" if response_data else "Similar property not found"
			return {
						"operation":"Search", 
						"message":response_msg ,
						"total_records":len(response_data),
						"data":response_data, 
						"user_id":request_data.get("user_id")
					}
		except elasticsearch.ElasticsearchException,e:
			raise ElasticSearchException(e.error)
		except Exception,e:
			raise OperationFailed("Get Similar property Operation Failed")	 
开发者ID:pawaranand,项目名称:propshikhari,代码行数:29,代码来源:propshikari_api.py

示例4: get_property_of_particular_tag

def get_property_of_particular_tag(request_data):
	if request_data:
		request_data = json.loads(request_data)
		if not request_data.get("tag"):
			raise MandatoryError("Mandatory Field Tag missing")
		try:
			
			exclude_list = ["agent_name", "agent_no", "contact_no", "contact_person", "created_by", 
				"modified_by", "creation_date", "modified_date", "posted_datetime", "modified_datetime"]

			must_clause_list = [{ "match":{ "tag":request_data.get("tag") } }, { "match":{ "status":"Active" } } ] 	
			search_query = { "query":{ "bool":{ "must":must_clause_list } } } 
			es = ElasticSearchController()
			response_data, total_records = es.search_document(["property"], search_query, request_data.get("page_number",1), request_data.get("records_per_page",40),exclude_list)	
			putil.show_amenities_with_yes_status(response_data)

			msg = "Property found for specfied criteria" if len(response_data) else "Property not found"
			response_dict = putil.init_pagination_and_response_generatrion(request_data, response_data, msg, total_records)
			response_dict["tag"] = request_data.get("tag")
			return response_dict

		except elasticsearch.ElasticsearchException,e:
			raise ElasticSearchException(e.error)
		except Exception,e:
			raise OperationFailed("Get Tagged Property Operation Failed")
开发者ID:pawaranand,项目名称:propshikhari,代码行数:25,代码来源:propshikari_api.py

示例5: store_request_in_elastic_search

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
开发者ID:pawaranand,项目名称:propshikhari,代码行数:28,代码来源:propshikari_api.py

示例6: get_property_contact

def get_property_contact(request_data):

	"""
		Get Contact person name, contact_no form property &
		generate lead & enquiry against that user. 

	"""

	if request_data:
		request_data = json.loads(request_data)
		email = putil.validate_for_user_id_exists(request_data.get("user_id"))	
		if not request_data.get("property_id"):
			raise MandatoryError("Mandatory Field Property Id missing")
		try:
			es = ElasticSearchController()
			response = es.search_document_for_given_id("property",request_data.get("property_id"),[],[])
			new_response = { "contact_no": response.get("contact_no"), "contact_person":response.get("contact_person")}
			create_lead_from_userid(request_data, email, response)
			return {	
						"operation":"Search",
						"message":"Contact Details found" if len(new_response) else "Contact Details Not Found", 
						"user_id":request_data.get("user_id"), 
						"data":new_response
					}
		except elasticsearch.TransportError:
			raise DoesNotExistError("Property Id does not exists")
		except Exception,e:
			raise e
开发者ID:pawaranand,项目名称:propshikhari,代码行数:28,代码来源:propshikari_api.py

示例7: get_alerts_based_on_last_request

def get_alerts_based_on_last_request(request_data, email):
	
	"""
		Generate search query from last search request of that user &
		check for properties which are posted from last month only. 
	"""

	try:
		search_query = {	
							"sort": [{ "posted_datetime": { "order": "desc" }}],
							"query":{ "bool":{ "must":[ {"match":{ "user_id":request_data.get("user_id")  } } ] }    } 
						}						
		es = ElasticSearchController()
		response_data, total_records = es.search_document(["request"], search_query, 1, 1)
		if response_data:
			last_month_date = add_months(datetime.datetime.now() ,-1).strftime("%Y-%m-%d %H:%M:%S")
			property_search_query = response_data[0].get("search_query")
			property_search_query = ast.literal_eval(property_search_query.encode("utf8"))
			new_query = property_search_query.get("query").get("bool").get("must")
			new_query.append({
								    "range" : {
								        "modified_datetime" : {
								            "gte":last_month_date,
								        }
								    }
								})
			property_search_query["query"]["bool"]["must"] = new_query
			uom = response_data[0].get("unit_of_area")
			uom = "Sq.Ft." if uom not in ["Sq.Ft.", "Acres", "Hectares"] else uom
			return property_search_query,  uom
		else:
			raise OperationFailed("No Alerts and Request Id found against User {0}".format(email))
	except elasticsearch.ElasticsearchException,e:
		raise ElasticSearchException(e.error)
开发者ID:pawaranand,项目名称:propshikhari,代码行数:34,代码来源:propshikari_api.py

示例8: get_user_properties

def get_user_properties(request_data):
	if request_data:
		request_data = json.loads(request_data)
		email = putil.validate_for_user_id_exists(request_data.get("user_id"))
		search_query =  { "query": { "match":{ "posted_by":request_data.get("user_id") } } }
		try:

			# fields_to_be_excluded from response and resultset generation 

			include_list = ["property_photo", "city", "location", "carpet_area", "amenities", "no_of_floors", "price", "status",
					"floor_no", "price_per_sq_ft", "property_id", "property_title", "tag", "possession_status", "property_subtype_option"]
			
			es = ElasticSearchController()
			response_data, total_records  = es.search_document(["property"], search_query, request_data.get("page_number",1), request_data.get("records_per_page",40), [], include_list)
			response_data = check_for_shortlisted_property(response_data, request_data.get("user_id"))
			putil.show_amenities_with_yes_status(response_data)

			# response data & pagination logic

			msg = "User Property Found" if len(response_data) else "User Property not found"
			return putil.init_pagination_and_response_generatrion(request_data, response_data, msg, total_records)

		except elasticsearch.ElasticsearchException,e:
			raise ElasticSearchException(e.error)
		except Exception,e:
			raise OperationFailed("Get User Properties Operation Failed")
开发者ID:pawaranand,项目名称:propshikhari,代码行数:26,代码来源:propshikari_api.py

示例9: get_shortlisted_property

def get_shortlisted_property(request_data):
	if request_data:
		request_data = json.loads(request_data)
		
		# Check if shortlisted property existed against user 

		email = putil.validate_for_user_id_exists(request_data.get("user_id"))
		property_ids_list = frappe.db.get_values("Shortlisted Property", {"user_id":request_data.get("user_id"), "status":"Active"}, "property_id")
		if not property_ids_list:
			return {"operation":"Search", "message":"No Single Shortlisted property found", "user_id":request_data.get("user_id")}
		property_ids_list = [ property_id[0] for property_id in property_ids_list if property_id]
		try:
			# generate search_query and resultset & fields to be included in response 

			sp_include_fields= ["property_photo", "city", "location", "carpet_area", "amenities", "no_of_floors", 
								"price", "status","floor_no", "price_per_sq_ft", "property_id", "property_title", 
								"tag", "possession_status", "property_subtype_option", "unit_of_area", "property_age"]

			search_query = { "query":{ "ids":{ "values":property_ids_list } }  } 
			es = ElasticSearchController()
			response_data, total_records = es.search_document(["property"], search_query, request_data.get("page_number",1), 
																request_data.get("records_per_page",40), [], sp_include_fields)	
			
			# response data & pagination logic 

			append_shortlisted_tag(response_data)
			msg = "Shortlisted Property Found" if len(response_data) else "Shortlsited Property not found"
			return putil.init_pagination_and_response_generatrion(request_data, response_data, msg, total_records)

		except elasticsearch.ElasticsearchException,e:
			raise ElasticSearchException(e.error)
		except Exception,e:
		 	raise OperationFailed("Get Shortlisted Property Operation Failed")
开发者ID:pawaranand,项目名称:propshikhari,代码行数:33,代码来源:propshikari_api.py

示例10: search_unpublished_property

def search_unpublished_property(data):
	
	property_data = json.loads(data)
	
	try:	
		# generate search query & result generation & list of fields which should be excluded.

		exclude_list = putil.get_exclude_list_for_search(property_data.get("request_source", ""))

		#must_clause_list.append([{"match":{ "published_status": "Unpublished" } }, { "match": { "status": "Deactivated" }}])
		must_clause_list= [{"match":{ "published_status": "Unpublished" } }]
		search_query = { "query":{ "bool":{ "must":must_clause_list } }, "sort": [{ "posted_datetime": { "order": "desc" }}] }
		
		es = ElasticSearchController()
		response_data, total_records = es.search_document(["property"], search_query, property_data.get("page_number",1), 
										property_data.get("records_per_page",40), exclude_list)
		
		if property_data.get("user_id") != "Guest":				
			response_data = check_for_shortlisted_property(response_data,property_data.get("user_id"))
		response_data = putil.get_date_diff_and_count_from_posting(response_data)
		putil.convert_area_according_to_uom(response_data, property_data.get("unit_of_area", "Sq.Ft."))
		putil.show_amenities_with_yes_status(response_data)
		
		# response data & pagination logic

		msg = "Property found for specfied criteria" if len(response_data) else "Property not found"
		response_dict = putil.init_pagination_and_response_generatrion(property_data, response_data, msg, total_records)
		return response_dict

	except elasticsearch.RequestError,e:
		raise ElasticInvalidInputFormatError(e.error)
开发者ID:arpitjain06,项目名称:propshikhari,代码行数:31,代码来源:propshikari_api.py

示例11: share_property

def share_property(request_data):
	if request_data:
		request_data = json.loads(request_data)
		email = putil.validate_for_user_id_exists(request_data.get("user_id"))
		user_name = frappe.db.get_value("User", {"user_id":request_data.get("user_id")}, ["first_name", "last_name"],as_dict=True)
		putil.validate_property_data(request_data, ["comments", "email_id"])		
		try:
			property_ids_list = {  comment.get("property_id"):comment.get("comment","")  for comment in request_data.get("comments") if comment.get("property_id")}
			search_query = { "query":{ "ids":{ "values":property_ids_list.keys() } }} 
			es = ElasticSearchController()
			response_data, total_records = es.search_document(["property"], search_query, request_data.get("page_number",1), request_data.get("records_per_page",40))				
			if response_data:
				for response in response_data:
					response["comments"] = property_ids_list.get(response.get("property_id"),"")
				args = { "title":"Property Shared by  {0}".format(email) , "property_data":response_data ,"first_name":user_name.get("first_name"), "last_name":user_name.get("last_name")}
				send_email(request_data.get("email_id"), "Propshikari properties shared with you", "/templates/share_property_template.html", args)
				return { "operation":"Share", "message":"Property Shared"}
			else:
				raise DoesNotExistError("Property Id does not exists in elastic search")
		except frappe.OutgoingEmailError:
			raise OutgoingEmailError("Email can not be sent,Outgoing email error")
		except elasticsearch.TransportError:
			raise DoesNotExistError("Property Id does not exists")
		except elasticsearch.ElasticsearchException,e:
			raise ElasticSearchException(e.error)
		except Exception,e:
			raise OperationFailed("Share Property Operation Failed")
开发者ID:pawaranand,项目名称:propshikhari,代码行数:27,代码来源:propshikari_api.py

示例12: get_location_details_for_map

def get_location_details_for_map(request_data):
	request_data = json.loads(request_data)
	email = putil.validate_for_user_id_exists(request_data.get("user_id"))
	putil.validate_property_data(request_data, ["request_id"])
	try:
		es = ElasticSearchController()
		response = es.search_document_for_given_id("request",request_data.get("request_id"),[],
														["search_query", "unit_of_area", "adv_search_query"])
		search_query = ast.literal_eval(response.get("adv_search_query").encode("utf8"))
		uom = response.get("unit_of_area")

		include_fields = ["property_title", "property_id", "location", "property_subtype_option",
			                      "operation", "carpet_area", "price", "geo_location_lat", "geo_location_lon" ]

		size = get_count_of_property_records(es)            
		response_data, total_records = es.search_document(["property"], search_query, 1, size, [], include_fields)
		uom = "Sq.Ft." if uom not in ["Sq.Ft.", "Acres", "Hectares"] else uom
		putil.convert_area_according_to_uom(response_data, uom)
		response_msg = "User Property Found" if response_data else "User property not found"
		return {
					"operation":"Search",
					"user_id":request_data.get("user_id"),
					"message":response_msg,
					"data":response_data
				}
	except elasticsearch.TransportError:
		raise DoesNotExistError("Request Id does not exists")
	except elasticsearch.ElasticsearchException,e:
		raise ElasticSearchException(e.error)
开发者ID:pawaranand,项目名称:propshikhari,代码行数:29,代码来源:propshikari_api.py

示例13: delete_multiple_photos

def delete_multiple_photos(data):
	data = json.loads(data)
	full_size_img = [img_url.replace("thumbnail", "regular") for img_url in data.get("img_list")]
	
	prop_dict = {"user_id":data.get("user_id"), "sid":data.get("sid"), "property_id":data.get("property_id")}
	
	doc = get_property_details(json.dumps(prop_dict))
	property_photo = get_property_photo(data.get("img_list"),doc.get("data").get("thumbnails"))
	
	update_query = get_script_query_for_multiple(full_size_img,data.get("img_list"),property_photo)
	
	if not doc.get("data").get("project_id",""):
		map(lambda img_url:delete_photo_from_propshikari(img_url),data.get("img_list")) 
	es = ElasticSearchController()
	response = es.update_docuemnt("property", data.get("property_id"), update_query)
	prop_dict = {"user_id":data.get("user_id"), "sid":data.get("sid"), "property_id":data.get("property_id"), 
					"fields":["thumbnails", "full_size_images", "property_photo"]}
	prop_response = get_property_details(json.dumps(prop_dict))
	
	return { 
				"message":"Property Photo deleted successfully",
				"full_size_images":prop_response.get("data").get("full_size_images", []),
				"thumbnails":prop_response.get("data").get("thumbnails", []),
				"property_photo":prop_response.get("data").get("property_photo", [])
			}
开发者ID:arpitjain06,项目名称:propshikhari,代码行数:25,代码来源:property_update_api.py

示例14: search_project

def search_project(request_data):
	if request_data:
		project_data = json.loads(request_data)
		project_data = putil.validate_property_posting_data(project_data,"property_json/project_search.json")
		putil.isolate_city_from_location(project_data)
		search_query = putil.generate_project_search_query(project_data)
		try:
			es = ElasticSearchController()
			response_data, total_records = es.search_document(["project"], search_query, project_data.get("page_number",1), project_data.get("records_per_page",40))
			request_id = store_request_in_elastic_search(project_data, search_query, "Project Search")
			response_data = putil.get_date_diff_from_posting(response_data)
			response_msg = "Project found for specfied criteria" if len(response_data) else "Project not found"
			from_record = (project_data.get("page_number",1) - 1) * cint(project_data.get("records_per_page",40)) + 1
			no_of_pages = math.ceil(flt(total_records)/project_data.get("records_per_page",40))
			return {	
						"operation":"Search",
						 "message":response_msg ,
						 "total_records":total_records, 
						 "request_id":request_id, 
						 "records_per_page":project_data.get("records_per_page",40),
						 "from_record":from_record ,
						 "to_record":from_record +  len(response_data) - 1 if response_data else from_record + project_data.get("records_per_page",40) - 1,
						 "data":response_data, 
						 "user_id":project_data.get("user_id"), 
						 "no_of_pages":no_of_pages
					 }
		except elasticsearch.RequestError,e:
			raise ElasticInvalidInputFormatError(e.error)
		except elasticsearch.ElasticsearchException,e:
			raise ElasticSearchException(e.error)
开发者ID:Tejal011089,项目名称:propshikhari,代码行数:30,代码来源:project_api.py

示例15: get_search_query_of_property_id

def get_search_query_of_property_id(request_data):
	try:
		es = ElasticSearchController()
		response = es.search_document_for_given_id("property",request_data.get("id"))		
		search_query = putil.generate_search_query_from_property_data(response)
		return search_query, "Sq.Ft."
	except elasticsearch.TransportError:
		raise DoesNotExistError("Property Id does not exists")
	except elasticsearch.ElasticsearchException,e:
		raise ElasticSearchException(e.error)	
开发者ID:pawaranand,项目名称:propshikhari,代码行数:10,代码来源:propshikari_api.py


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