# -*- coding: utf-8 -*-

from datetime import datetime
from elasticsearch_dsl import DocType, Date, Integer, Keyword, Text
from elasticsearch_dsl.connections import connections

# Define a default Elasticsearch client
connections.create_connection(hosts=['localhost'])

from models.models import Article

s = Article.search()
s = s.suggest('title_suggestion',
              'python',
              completion={
                  'field': 'title_suggest',
                  'fuzzy': {
                      'fuzziness': 2
                  },
                  'size': 10
              })
suggestions = s.execute_suggest()
for match in suggestions.title_suggestion[0].options:
    source = match._source
    print(source['title'], match._score)
# Display cluster health
# print(connections.get_connection().cluster.health())

# from elasticsearch_dsl import Keyword, Mapping, Nested, Text
#
# m = Mapping('article')