0

I need to add another param 'type' to my query to filter with

This is what I have right now and it works for me:

    conn = pyes.ES(settings.ES_URL)
    query_string = self.request.GET['q'].lower()
    type = self.request.GET['type'].lower()#not used yet!

    ...

    query1 = pyes.MultiMatchQuery(self.FIELDS_SEARCH, query_string, operator='and')

    search1 = pyes.Search(query=query1, filter=filters, fields=self.RESPONSE_FIELDS, size=num, index_boost=1)

    response = conn.search_multi([search1, search2], indices_list=[es_alias] * 2, doc_types_list=['asset', 'people'] * 2)

    response._do_search()

How can I add filtering by param "type"?

Armance
  • 5,350
  • 14
  • 57
  • 80

1 Answers1

0

I think you are looking for bool query

query1 = pyes.MultiMatchQuery(self.FIELDS_SEARCH, query_string, operator='and')

typequery = pyes.QueryStringQuery(query="type_value",default_field="type")

combinequery = pyes.BoolQuery(must=[query1, typequery])

searchquery = pyes.Search(query=combinequery,filter=filters, fields=self.RESPONSE_FIELDS, size=num, index_boost=1)

Here is the link to query string, you can replace must with should if you want OR condition.

Does this help?

ChintanShah25
  • 12,366
  • 3
  • 43
  • 44
  • Thanks, but I still need to keep "search2", do I just replace "search1" with "searchquery" that you wrote like this: `conn.search_multi([serachquery , search2])` ? – Armance Jan 13 '16 at 15:22
  • although I am not 100%, try replacing it. It should work going by the ES api for multiple search but I am not abel to find docs for pyes for multi_search, could you help me find it? – ChintanShah25 Jan 13 '16 at 15:37
  • But if I replace `search1 = pyes.Search(query=query1, filter=filters, fields=self.RESPONSE_FIELDS, size=num, index_boost=1)` by `searchquery = pyes.Search(query=combinequery)` how about all the params I have in search1 (filter,fields,size and index) ?? – Armance Jan 13 '16 at 15:40
  • here : http://pyes.readthedocs.org/en/latest/references/pyes.es.html#pyes.es.ES.search_multi – Armance Jan 13 '16 at 15:44
  • P.S: QueryStringQuery is not working sine I use pyes==0.20.1 (yeah I know!! I can't update now) – Armance Jan 13 '16 at 16:24
  • I replaced it with StringQuery – Armance Jan 13 '16 at 16:31
  • Yes, you can put all the params in it, I have edited my answer, then replace search1 with searchquery, let me know if it doesn't work. – ChintanShah25 Jan 13 '16 at 17:46