elasticsearch,django-haystack,Django,elasticsearch,Django Haystack" /> elasticsearch,django-haystack,Django,elasticsearch,Django Haystack" />

Django 我不知道';我不理解';s从elasticsearch/haystack返回

Django 我不知道';我不理解';s从elasticsearch/haystack返回,django,elasticsearch,django-haystack,Django,elasticsearch,Django Haystack,在我看来,使用elasticsearch后端从haystack返回的结果是错误的。我的搜索索引如下: from haystack import indexes from .models import IosVideo class VideoIndex(indexes.SearchIndex, indexes.Indexable): text = indexes.CharField(document=True, use_template=True)

在我看来,使用elasticsearch后端从haystack返回的结果是错误的。我的搜索索引如下:

from haystack import indexes
from .models import IosVideo

class VideoIndex(indexes.SearchIndex, indexes.Indexable):                   
    text = indexes.CharField(document=True, use_template=True)              
    title = indexes.CharField(model_attr='title')                           
    absolute_url = indexes.CharField(model_attr='get_absolute_url')         
#    content_auto = indexes.EdgeNgramField(model_attr='title')              
    description = indexes.CharField(model_attr='description')               
#    thumbnail = indexes.CharField(model_attr='thumbnail_url', null=True)   

    def get_model(self):                                                    
        return IosVideo                                                     

    def index_queryset(self, using=None):                                   
        return self.get_model().objects.filter(private=False)  
我的文本文档看起来像:

{{ object.title }}
{{ object.text }}
{{ object.description }}
我的问题是

SearchQuerySet().models(IosVideo).filter(content="darby")[0]
返回的结果使我认为这不起作用,是一个具有以下特征的视频对象

title: u'Cindy Daniels'
description: u'',
text: u'Cindy Daniels\n\n\n',
absolute_url: u'/videos/testimonial/cindy-daniels/'
究竟为什么查询会返回这样的结果?我很困惑

我目前的理论是,它将查询中字符的每个子集标记化,并将其用作部分匹配。是否有办法降低该公差,使其更接近匹配

我的pip信息是 elasticsearch==1.2.0 django haystack==2.3.1

elasticsearch版本号为1.3.1

另外,当我用

它返回10个结果

SearchQuerySet().filter(content="darby")  
返回4k结果


有人知道什么会导致这种行为吗

django haystack 2.1.0的Charfield索引的filter()方法有问题。您可以将它们改为NgramField,例如
text=index.NgramField(document=True,template\u name=True)


问题是,当你使用这个组合时,你只会得到第一个字符。因此,它将返回文本索引字段中有“d”的所有匹配项。

您是使用elasticstack还是自定义分析器?这可能解释了你看到的结果。我相信您已经看到了,但是从Haystack2.X开始,过滤器中的默认查找是
contains
,而不是
exact
。再加上一个查看部分单词的分析器,可能会与该文档匹配。没有自定义分析器:(我的pip看起来像elasticsearch==1.2,django haystack==2.3.1。elasticsearch版本是1.3.1。您是否尝试直接查询elasticsearch来比较结果?例如
http://localhost:9200/_search/?q=darby
其中
search
是您的索引名。您是否检查了elasticsearch contai中的索引文档n、 在本例中,例如Cindy Daniels的文档?@LucasMoeskops返回10个结果,但这些结果都不是Cindy Daniels对象。因此Haystack有很大问题,对吗?