コード例 #1
0
ファイル: es.py プロジェクト: lightbase/ckanext-datadaemon
    def types_create(self):
        """
        Create datasets as types inside Elastic Search
        """
        # Check if default indice is already created
        indice_info = self.check_indice(self.indice)

        if not indice_info:
            # Fail here
            raise Exception('Indice not created to store datasets as types. Create this indice first: %s' % self.indice)

        # Now try to create types
        ckanclient = self.load_ckanclient()
        package_list = ckanclient.package_register_get()
        for package in package_list:
            # FIXME: I'm hard-coding some properties. Have to remove it from here fast
            mapping = {
                "properties": {
                    "data" : {
                        "type" : "date",
                        "index" : "not_analyzed"
                     }

                 }
              }
            # Now create each one separatelly as a type
            client = self.load_elastic_config('%s/%s' % (self.indice, package))

            # send the request
            response = client.mapping_update(mapping)

        # Return last response
        return response
コード例 #2
0
ファイル: es.py プロジェクト: lightbase/ckanext-datadaemon
    def indices(self, old=None):
        """
        Get ES indexes for ckan datasets
        
        @param old: supplied if you want to see old mapping
        """
        ckanclient = self.load_ckanclient()
        package_list = ckanclient.package_register_get()
        client = self.load_elastic_config()
        es_mapping = client.mapping()
        out_list = list()
        for package in package_list:
            # Do we want old or new mapping
            if old:
                if package in es_mapping.keys():
                    # Add it to package out list
                    out_list.append(package)
            else:
                if es_mapping.get(self.indice):
                    # Look for the package as a type inside index
                    if package in es_mapping[self.indice].keys():
                        out_list.append(package)
                    else:
                        # indice not created. Complain about it
                        raise Exception('You have to create indice first. Execute indice_create')

        # Return list of indices
        return out_list