0

我在我的 django 应用程序中使用 ElasticSearch-DSL,查询仅返回 10 行。当我使用尺寸时。我收到错误“multi_match”查询不支持大小。

from django.shortcuts import render
from elasticsearch_dsl import Q
from elasticsearch_dsl.query import MultiMatch
# Create your views here.
from search.documents import CarDocument
from products.models import Products

def search(request):
   q = request.GET.get('q')
   if q:
       #cars = CarDocument.search().query("match", model_name=q)
      q = request.GET.get('q', None)
      query1 = MultiMatch(query=q,  fields=['product_make', 'bodystyle','model_name','variant','transmission','yom'])
      s = CarDocument.search().query(query1)
      cars = s.execute()
   else:
      cars = ''

   return render(request, 'search/search.html', {'cars': cars})
4

2 回答 2

2

这样,您将获得所有记录:

s = CarDocument.search().query(query1)
total = s.count()
s = s[0:total]
cars = s.execute()
于 2021-05-12T11:59:37.373 回答
1

默认情况下,它返回 10 个数据。如果你想要超过 10 个数据,比如获得 50 个数据,你可以使用CarDocument.search()[:50]

于 2019-11-24T02:45:39.393 回答