コード例 #1
0
ファイル: views.py プロジェクト: egyedgabor/Galbana
def elastic():
    connections.configure(default={
        'hosts': os.environ['ELASTICSEARCH_HOST'],
        'port': os.environ['ELASTICSEARCH_PORT'],
        'use_ssl': True,
        'verify_certs': True,
        'ca_certs': '/run/secrets/ca.crt',
        'client_cert': '/run/secrets/certificate.crt',
        'client_key': '/run/secrets/certificate.key'
    }, )

    es = Elasticsearch(host=os.environ['ELASTICSEARCH_HOST'],
                       port=os.environ['ELASTICSEARCH_PORT'],
                       use_ssl=True,
                       verify_certs=True,
                       ca_certs='/run/secrets/ca.crt',
                       client_cert='/run/secrets/certificate.crt',
                       client_key='/run/secrets/certificate.key')
    try:
        es.info()
    except es_exceptions.ConnectionError:
        return error('Please check Elasticserach service, %s:%s' %
                     (os.environ['ELASTICSEARCH_HOST'],
                      os.environ['ELASTICSEARCH_PORT']))
    return ({'response': es, 'status': 'OK'})
コード例 #2
0
    def __init__(self, host: Union[list, str] = None, prefix: str = '', **kwargs) -> None:
        self._exists = set()
        self._mirror = False
        self._models = {}
        self._prefix = self._clean_string(prefix)

        if host is not None:
            self._mirror = True
            connections.configure(
                default=dict(
                    hosts=host,
                    timeout=kwargs.get('timeout', 60)
                )
            )
コード例 #3
0
    def ready(self):
        from django.conf import settings
        from ...serializer import Serializer
        from ...utils import register_serializers
        from .settings import (ESDOCS_SERIALIZER_MODULES,
                               ESDOCS_SERIALIZER_COMPATIBILITY_HOOKS,
                               ESDOCS_USING, ESDOCS_CONNECTIONS)

        from elasticsearch_dsl import connections
        # TODO: perhaps have some more elaborate multi-client creation steps here, based on settings?
        # then, we can pass in the 'default' client into `register_serializers`
        connections.configure(**ESDOCS_CONNECTIONS)
        client = connections.get_connection(ESDOCS_USING)

        # this loads the serializers and initializes compatibility hooks
        register_serializers(ESDOCS_SERIALIZER_MODULES, client=client)
        Serializer.register_hooks(ESDOCS_SERIALIZER_COMPATIBILITY_HOOKS)
コード例 #4
0
from elasticsearch_dsl import Document, Search, connections, Text, Boolean

# name of index(like table)
IP_PORT_SERVER = '192.168.197.251:9200'
INDEX = 'pepito54'

connections.create_connection(timeout=60)

connections.configure(default={
    'hosts': IP_PORT_SERVER,
})

client = connections.get_connection()


class Link(Document):
    url = Text()
    text = Text()
    type = Text()
    crawled = Boolean()

    class Index:
        name = INDEX


def save(dataDict):
    if not Link._index.exists():
        Link.init()

    newlink = Link()
コード例 #5
0
from django_elasticsearch_dsl import Document
from django_elasticsearch_dsl.registries import registry
from .models import IR2
from elasticsearch_dsl import connections
from datetime import datetime
connections.configure(default={'hosts': 'localhost'},
                      dev={
                          'hosts': ['http://localhost:9200'],
                          'sniff_on_start': True
                      })


@registry.register_document
class IR2(Document):
    class Index:
        name = 'face_system'

        settings = {'number_of_shards': 1, 'number_of_replicas': 0}

    class Django:
        model = IR2
        fields = [
            'iddata',
            'name',
            'description',
            'university',
        ]


for x in range(0, 100):
    name1 = IR2(iddata=x, name=x, description="famous human", university="UIT")
コード例 #6
0
import sys, getopt
from .scanner import scan_path
from .config import get_config, save_config
from elasticsearch_dsl import connections
import os
from .web import make_app
from waitress import serve

connections.configure(default={'hosts': 'localhost'})


def main():
    pass


def scanner_main():
    OPTIONS = "m:"
    args = dict(get_args(OPTIONS, []))
    mount = os.path.abspath(args['-m'])
    if os.path.exists(mount):
        scan_path(mount)
        config = get_config()
        mounts = config.get('mounts', [])

        if mount not in mounts:
            mounts.append(mount)
            config['mounts'] = mounts
            save_config(config)


def web_main():
コード例 #7
0
from elasticsearch import Elasticsearch, RequestsHttpConnection
from elasticsearch_dsl import connections
from cpchain.utils import config

es_hosts_string = config.market.es_hosts or '192.168.0.132:9200'
es_hosts = es_hosts_string.split()

# used by elasticsearch
es_client = Elasticsearch(hosts=es_hosts,
                          connection_class=RequestsHttpConnection)
# used by elasticsearch_dsl
connections.configure(default={'hosts': es_hosts_string}, )
コード例 #8
0
ファイル: apps.py プロジェクト: michael-barbour/factotum
 def ready(self):
     connections.configure(**self._lower_dict(settings.ELASTICSEARCH))
コード例 #9
0
FORM_RENDERER = 'django.forms.renderers.TemplatesSetting'

# Database
# https://docs.djangoproject.com/en/1.11/ref/settings/#databases

DATABASES = {
    # fail if no DATABASE_URL - don't use a default value
    'default': env.db(),
}

# Elasticsearch
# http://elasticsearch-dsl.readthedocs.io/en/6.1.0/configuration.html

connections.configure(default={
    'hosts': env('ELASTICSEARCH_URL'),
}, )

# Password validation
# https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME':
        'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME':
        'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
コード例 #10
0
ファイル: model.py プロジェクト: Wjun0/python_elasticsearch
from elasticsearch_dsl import connections, Document, Integer, Text, Keyword, Date

connections.configure(default={"hosts": "192.168.59.138:9200"})


class Test_index(Document):
    pk = Integer()
    name = Text(analyzer='snowball')

    class Index:
        name = "wj-index"  # es 版本不同使用的名字不一样,以前版本使用index
        settings = {
            "number_of_shards": 2,  #设置分片数
        }


class Blog(Document):
    title = Text()
    text = Text()
    date = Text()

    class Index:
        name = "website"


if __name__ == '__main__':
    # 创建索引
    Test_index.init()
コード例 #11
0
)
from elasticsearch_dsl.query import (
    SpanNear,
    SpanTerm
)

# Read the json File
json_data = open('titles.json').read()
data = json.loads(json_data)

docs = data['response']['docs']


# create a new default elasticsearch connection
connections.configure(
    default={'hosts': 'localhost:9200'},
)

# create a new custom filter for lowercase in turkish
turkish = analysis.token_filter('turkish_lowercase', type="lowercase", language="turkish")

# create a custom analyzer for turkish lowercase
turkish_lowercase = analyzer('turkish_lowercase',
    type = "custom",
    tokenizer="whitespace",
    filter=[turkish],
)

class Document(DocType):
    title = Text(
        analyzer = turkish_lowercase,