question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't achieve autocomplete

See original GitHub issue

Hello, I am struggling with autocomplete for a long time. Simply i am loading list of cities to the elasticsearch, i am printing first index so i am sure that Novinki city exists there. And when I do the execute suggest I receive no completion for text “Novin”. I was refering to official tutorial - http://elasticsearch-dsl.readthedocs.io/en/latest/persistence.html Can someone give me a tip what I am doing wrong? Thank you

import json
from elasticsearch_dsl import Search, Index, DocType, Text, Completion
from elasticsearch_dsl.connections import connections


connections.create_connection(hosts=['localhost'])

with open('city_list.json') as json_data:
    cities_json = json.load(json_data)

cities = Index('cities')
cities.delete(ignore=404)
cities.create()


@cities.doc_type
class City(DocType):
    name = Text()
    name_suggest = Completion()
    country = Text()

    class Meta:
        doc_type = 'city'

City.init()

for index, city in enumerate(cities_json['cities']):
    if index == 1:
        print(city) # this prints {'coord': {'lon': 37.666668, 'lat': 55.683334}, 'name': 'Novinki', 'id': 519188, 'country': 'RU'}
    city = City(name=city['name'], country=city['country'])
    city.save()

s = City.search()
s = s.suggest('name_suggestions', 'Novin', completion={'field': 'name_suggest'})
suggestions = s.execute_suggest()
for result in suggestions.name_suggestions:
    print('Suggestions for %s:' % result) # this gives me Suggestions for {'length': 5, 'options': [], 'offset': 0, 'text': 'Novin'}:

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
marcelometalcommented, Oct 30, 2018

Hi @HonzaKral ,

I tried to use the analyzer argument in the Completion class, but it fails like one of the comments above:

.../elasticsearch_dsl/mapping.py", line 99, in _collect_analysis
    d = analyzer.get_analysis_definition()
AttributeError: 'str' object has no attribute 'get_analysis_definition'

This is my code:

political_party = Text(
    fields={
        'keyword': Keyword(),
        'suggest': Completion(analyzer=analyzer('brazilian')),
    }
)

I’ve debugged the code and I fixed it adding the _param_defs in the Completion class

 class Completion(Field):
+    _param_defs = {
+        'analyzer': {'type': 'analyzer'},
+    }
     name = 'completion'

I don’t know if it is the best approach, but with some guidance I can open a PR.

PS: the elasticsearch-dsl-py version is 6.2.1

1reaction
honzakralcommented, Dec 7, 2017

My bad, please use:

from elasticsearch_dsl import analyzer
analyzer('keyword')
Read more comments on GitHub >

github_iconTop Results From Across the Web

AutoComplete not working correctly - Outlook - Microsoft Learn
Check to see if AutoComplete is turned on · In Outlook, select File > Options. · Select the Mail tab. · Scroll roughly...
Read more >
jquery - Can't get $(this) working in jQueryUI autocomplete
Show activity on this post. I'm trying to create a generic autocomplete script using jQueryUI. The autocomplete should work for every: <input type='text'...
Read more >
Manage Google autocomplete predictions - Google Search Help
Learn more about autocomplete. Turn off Personal results. Important: When Personal results are off, you won't get personalized predictions or recommendations ...
Read more >
Can't get Autocomplete to work [#3088539] | Drupal.org
Hi,. I have followed the steps in the Readme, and my full text search field is has to correct attributes (I guess). However,...
Read more >
Can't get autocomplete for dependencies · Issue #27 - GitHub
I am using swift package (SPM) with dependencies such as PerfectHTTPServer. is there any configuration I need to do to make autocomplete work?...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found