2017-01-28 2 views
0

私はdjangoの1つのモデルに対して自動完成のAPIを作成しようとしています。弾力性のある検索とhaystackを初めて使用する。オートコンプリート結果を取得しようとしているときにエラーが発生しました。オートコンプリートが動作していません弾性検索付きのはしもだ

Failed to query Elasticsearch using 'content_auto:(Jitney)': TransportError(400, u'parsing_exception', u'[query_string] query does not support [fuzzy_min_sim]') 

models.py

from __future__ import unicode_literals 

from django.db import models 


class Movie(models.Model): 
    title = models.CharField(max_length=250) 
    year = models.CharField(max_length=250) 
    location = models.CharField(max_length=250) 
    fun_fact = models.CharField(max_length=250, null=True) 
    production_company = models.CharField(max_length=250) 
    director = models.CharField(max_length=250) 
    actor1 = models.CharField(max_length=250) 
    actor2 = models.CharField(max_length=250, null=True) 
    actor3 = models.CharField(max_length=250, null=True) 
    longitude = models.DecimalField(max_digits=9, decimal_places=6) 
    latitude = models.DecimalField(max_digits=9, decimal_places=6) 

    class Meta: 
     db_table = "sf_movies" 

    def __str__(self): 
     return self.title 

search.py​​

from haystack import indexes 
from models import Movie 


class MovieIndex(indexes.SearchIndex, indexes.Indexable): 
    text = indexes.CharField(document=True, use_template=True) 
    year = indexes.CharField(model_attr='year') 

    content_auto = indexes.EdgeNgramField(model_attr='title') 

    def get_model(self): 
     return Movie 

    def index_queryset(self, using=None): 
     """Used when the entire index for model is updated.""" 
     return self.get_model().objects.all() 

views.py

from django.shortcuts import render 

# Create your views here. 
import json 
from django.http import HttpResponse 
from haystack.query import SearchQuerySet 


def autocomplete(request): 
    sqs = SearchQuerySet().autocomplete(content_auto=request.GET.get('q', ''))[:5] 
    suggestions = [result.title for result in sqs] 
    # Make sure you return a JSON object, not a bare list. 
    # Otherwise, you could be vulnerable to an XSS attack. 
    the_data = json.dumps({ 
     'results': suggestions 
    }) 
    return HttpResponse(the_data, content_type='application/json') 

ディレクトリ構造

私はrebuild_indexコマンドを実行すると
. 
── app 
│   ├── __init__.py 
│   ├── admin.py 
│   ├── apps.py 
│   ├── migrations 
│   │   ├── 0001_initial.py 
│   │   ├── __init__.py 
│   ├── models.py 
│   ├── search.py 
│   ├── template 
│   │   └── search 
│   │    └── indexes 
│   │     └── app 
│   │      └── movie_text.txt 
│   ├── tests.py 
│   ├── views.py 
├── db.sqlite3 
├── manage.py 
└── uber_assignment_SF_movies 
    ├── __init__.py 
    ├── settings.py 
    ├── settings.pyc 
    ├── urls.py 
    ├── wsgi.py 

movie_text.txt

{{ object.title }} 
{{ object.year }} 
{{ object.production_company }} 
{{ object.director }} 

は、私はここでの問題を見つけることができないのです何を出力

WARNING: This will irreparably remove EVERYTHING from your search index in connection 'default'. 
Your choices after this are to restore from backups or rebuild via the `rebuild_index` command. 
Are you sure you wish to continue? [y/N] y 
Removing all documents from your index because you said so. 
All documents removed. 
~ 

の下に取得します。

答えて

0

検索ファイル名に間違いがありました。私は "search_indexes.py"の代わりに "search.py​​"としてファイルを指定しました

関連する問題