import pydoc

from django.conf import settings
from django.apps import apps


def created_index_inelastic_search():
    """
    The index name will be located in settings
    """


def check_if_elastic_is_running():
    pass


def clear_index():
    pass


def updated_index():
    pass


def purge_index():
    pass


def serialize_model(obj):
    """
    Locates a models serializer and uses it to serializer a model instane
    This allows us to search a document through all its important components.
    If a attribute of model is important enough to appear in the serializer,
    it means that the models should also be searched though that attribute
    as well. This will take care for all the child models of a model if
    they have been inlined in the serializer.

    For this to work a model's serializer name should follow this convention
    '<model_name>Serializer'

    Only apps in local apps will be indexed.
    """
    app_label = obj._meta.app_label
    serializer_path = "{}{}{}{}".format(
        app_label, ".serializers.", obj.__class__.__name__, 'Serializer')
    serializer_cls = pydoc.locate(serializer_path)
    serialized_data = serializer_cls(obj).data
    return {
        "data": serialized_data,
        "index_type": obj.__class__.__name__.lower(),
        "id": str(obj.id)
    }



def index_instance(serialized_obj):
    pass


def failure_queues():
    pass


def process_failure_queue():
    pass


def index_in_realtime():
    pass


def index_periodically():
    pass


def get_document_from_index():
    pass


def search_document_in_index():
    pass

@@ -73,248 +73,819 @@
 pps%0A
-%0A%0Adef created_index_inelastic_search(
+import requests%0A%0AELASTIC_URL = settings.SEARCH.get('ELASTIC_URL')%0A%0A%0Aclass ElasticAPI(object):%0A    def setup_index(self, index_name
 ):%0A    
+ 
-%22%22%22%0A    The
+   url = ELASTIC_URL +
  index
- 
+_
 name
- will be located in settings%0A    %22%22%22%0A%0A%0Adef check_if_elastic_is_running():%0A    pass%0A%0A%0Adef clear_index(
+%0A        result = requests.put(url)%0A        return result%0A%0A    def get_index(self, index_name):%0A        url = ELASTIC_URL + index_name%0A        result = requests.get(url)%0A        return result%0A%0A    def delete_index(self, index_name
 ):%0A    
+ 
-pass%0A%0A%0Adef updated_index():%0A    pass%0A%0A%0Adef purge_index():%0A    pass
+   url = ELASTIC_URL + index_name%0A        result = requests.delete(url)%0A        return result%0A%0A    def index_instance(self, index_name, instane_data):%0A        instance_type = instane_data.get('instance_type')%0A        instance_id = instane_data.get('instance_id')%0A        url = ELASTIC_URL + index_name + instance_type + instance_id%0A        result = requests.put(url, instane_data)%0A        return result
 %0A%0A%0Ad
@@ -1885,283 +1885,4 @@
   %7D%0A
-%0A%0A%0Adef index_instance(serialized_obj):%0A    pass%0A%0A%0Adef failure_queues():%0A    pass%0A%0A%0Adef process_failure_queue():%0A    pass%0A%0A%0Adef index_in_realtime():%0A    pass%0A%0A%0Adef index_periodically():%0A    pass%0A%0A%0Adef get_document_from_index():%0A    pass%0A%0A%0Adef search_document_in_index():%0A    pass%0A

Add elasticsearch api.