def test_suggest_can_be_run_separately(data_client): s = Search() s = s.suggest('simple_suggestion', 'elasticserach', term={'field': 'organization'}) response = s.execute_suggest() assert response.success() assert response.simple_suggestion[0].options[0].text == 'elasticsearch'
def suggest(q, field, size=10): s = Search(using=es.client, index=es.index_name) s = s.suggest('suggestions', q, completion={ 'field': field, 'size': size, }) result = s.execute_suggest().to_dict() try: suggestions = result.get('suggestions', [])[0]['options'] return suggestions except (IndexError, AttributeError): return []