2

I have the following problem with the elasticsearch_dsl python library.

I am developing a web application (DJANGO framework) with search functionality. I want to build a dynamic query, must mode.

So here it is the following code

i = 0
must = []
while (i < len(results['words'])):
    must.append(Q('match', tags=results['words'][i]))
    i += 1

print must
client = Elasticsearch()
es = Search(using=client, index="_______")
es.query(must)
response = es.execute()
for hit in response:
    print hit
return response.hits.total

Python returns exceptions.TypeError

I have already the documentation of elasticsearch_dsl but i didn't find something like my issue. Do you know the way how i fix this problem?

4

1 に答える 1

1

あなたはちょっと近いです。このようにオブジェクトを指定boolしてクエリする必要がありますSearch

i = 0
must = []
while (i < len(results['words'])):
    must.append(Q('match', tags=results['words'][i]))
    i += 1

print must
client = Elasticsearch()
q = Q('bool', must=must)   <--- This is important
es = Search(using=client, index="_______").query(q)
response = es.execute()
for hit in response:
    print hit
return response.hits.total

es.to_dict()理解に役立つ実際のクエリも見ることができます

于 2016-01-11T00:56:04.577 に答える