old_contents: import json
  from django.http import HttpResponseForbidden
  
  from atlas.art.models import PackageTest, TestsInTasks
  from atlas.prodtask.models import ProductionTask
  from rest_framework.decorators import api_view, authentication_classes, permission_classes
  from rest_framework.response import Response
  from rest_framework.authtoken.models import Token
  from rest_framework.authentication import TokenAuthentication, BasicAuthentication
  from rest_framework.permissions import IsAuthenticated
  from rest_framework.decorators import parser_classes
  from rest_framework.parsers import JSONParser
  from django.shortcuts import render
  
  
  from elasticsearch import Elasticsearch
  from elasticsearch_dsl import Search
  from elasticsearch_dsl.connections import connections
  from atlas.settings.local import ESLogin
  
  connections.create_connection(hosts=['http://aiatlas171.cern.ch:9200'], http_auth=(ESLogin['login'],ESLogin['password']))
  
  def test_connection():
      return Search(index="prodsys", doc_type='MC16')
  
  
  @api_view(['POST'])
  def es_task_search(request):
      search_string = json.loads(request.body)
      response = keyword_search(key_string_from_input(search_string)['query_string'])
      result = []
      for hit in response:
          result.append(hit.to_dict())
      return Response(result)
  
  
  @api_view(['POST'])
  def search_string_to_url(request):
      search_string = json.loads(request.body)
      return Response(key_string_from_input(search_string))
  
  def key_string_from_input(search_string):
      prepared_strings = search_string['search_string'].replace('\n',',').replace('\r',',').replace('\t',',').replace(' ',',').split(',')
      query_string = ' AND '.join(['"'+x+'"' for x in prepared_strings if x])
      url = ','.join([x for x in prepared_strings if x])
      return {'url':url,'query_string':query_string}
  
  def index(request):
      if request.method == 'GET':
  
          return render(request, 'dkb/_index_dkb.html', {
                  'active_app': 'dkb',
                  'pre_form_text': 'DKB',
                  'title': 'DKB search',
                  'parent_template': 'prodtask/_index.html',
              })
  
  
  
  
  
  def keyword_search(keyword_string):
      es_search = Search(index="prodsys", doc_type='MC16')
      query = es_search.update_from_dict({'query':{'query_string':{"query": keyword_string,"analyze_wildcard":True}}})
      return query.execute()
new_contents: import json
  from django.http import HttpResponseForbidden
  
  from atlas.art.models import PackageTest, TestsInTasks
  from atlas.prodtask.models import ProductionTask
  from rest_framework.decorators import api_view, authentication_classes, permission_classes
  from rest_framework.response import Response
  from rest_framework.authtoken.models import Token
  from rest_framework.authentication import TokenAuthentication, BasicAuthentication
  from rest_framework.permissions import IsAuthenticated
  from rest_framework.decorators import parser_classes
  from rest_framework.parsers import JSONParser
  from django.shortcuts import render
  
  
  from elasticsearch import Elasticsearch
  from elasticsearch_dsl import Search
  from elasticsearch_dsl.connections import connections
  from atlas.settings.local import ESLogin
  
  connections.create_connection(hosts=['http://aiatlas171.cern.ch:9200'], http_auth=(ESLogin['login'],ESLogin['password']))
  
  def test_connection():
      return Search(index="prodsys", doc_type='MC16')
  
  
  @api_view(['POST'])
  def es_task_search(request):
      search_string = json.loads(request.body)
      response = keyword_search(key_string_from_input(search_string)['query_string'])
      result = []
      for hit in response[:10000]:
          result.append(hit.to_dict())
      return Response(result)
  
  
  @api_view(['POST'])
  def search_string_to_url(request):
      search_string = json.loads(request.body)
      return Response(key_string_from_input(search_string))
  
  def key_string_from_input(search_string):
      prepared_strings = search_string['search_string'].replace('\n',',').replace('\r',',').replace('\t',',').replace(' ',',').split(',')
      query_string = ' AND '.join(['"'+x+'"' for x in prepared_strings if x])
      url = ','.join([x for x in prepared_strings if x])
      return {'url':url,'query_string':query_string}
  
  def index(request):
      if request.method == 'GET':
  
          return render(request, 'dkb/_index_dkb.html', {
                  'active_app': 'dkb',
                  'pre_form_text': 'DKB',
                  'title': 'DKB search',
                  'parent_template': 'prodtask/_index.html',
              })
  
  
  
  
  
  def keyword_search(keyword_string):
      es_search = Search(index="prodsys", doc_type='MC16')
      query = es_search.update_from_dict({'query':{'query_string':{"query": keyword_string,"analyze_wildcard":True}}})
      return query
subject: Fix dkb es