我正在尝试在我的项目中实施elasticsearch。现在它能够搜索我的响应表中的响应字段,但我也希望能够搜索其他字段,例如问题,主题,客户。
当我尝试在字段下添加“问题”时,我的站点中断了。
documents.py:
from django_elasticsearch_dsl import DocType, Index, fields
from app.models import Response
@response_index20.doc_type
class ResponseDocument20(DocType):
class Meta:
model = Response
fields = [
'Response',
#'Question',
]
models.py:
class Response(models.Model):
Question = models.ForeignKey(Question, default=436, on_delete=models.CASCADE)
Topic = models.ForeignKey(Topic, default=13, on_delete=models.CASCADE)
Response = models.TextField()
Client = models.ForeignKey(ClientDetail, default=8, on_delete=models.CASCADE)
Planit_location = models.ForeignKey(Planit_location, default=1, on_delete=models.CASCADE)
Image = models.ForeignKey(Image, default=0, on_delete=models.CASCADE)
Date_added = models.DateField(default=datetime.date.today)
def __str__(self):
return self.Response
views.py:
from app.documents import ResponseDocument20
@login_required(login_url="/login/")
def search_es20(request):
q = request.GET.get('q')
if q:#ES
responses = ResponseDocument20.search().query("wildcard", Response=q)#ES
else:#ES
responses = ''#ES
return render(request, 'app/search_es20.html', {
'responses': responses,
'query': q,
})