我有一个仓库模型,它的索引如下

class WarehouseIndex(SearchIndex, Indexable):
    """
    SearchIndex Class that stored indexes for Model Warehouse
    """
    text = CharField(document=True, use_template=True)
    search_auto = NgramField()
    ....

   def get_model(self):
        return WareHouse

在我的 shell 中,我正在运行以下sqs查询。
>>> sqs = SearchQuerySet().models(WareHouse)
>>> sqs.filter(customers=3).filter(search_auto='pondicherry')

这将返回结果,其中包含没有确切术语pondicherry的结果,它还为我提供了一些与ichchendi等类似的术语匹配的结果。

我什至尝试使用__exactExact,但都返回相同的结果?

编辑:Index mappingIndex Setting

如何避免这种情况,仅提供pondicherry字词的结果?

最佳答案

似乎与此open issue有关

这是因为您的search_auto ngram字段具有相同的索引和搜索分析器,因此您的搜索字词pondicherry在搜索时也会得到ngram。解决此问题的唯一方法是为search_analyzer字段设置不同的search_autostandard非常合适。

您可以使用以下方法更改search_auto字段映射:

curl -XPUT localhost:9200/haystack/_mapping/modelresult -d '{
   "properties": {
      "search_auto": {
         "type": "string",
         "analyzer": "ngram_analyzer",
         "search_analyzer": "standard"
      }
   }
}'

10-05 23:28
查看更多