How to narrow deep by filter to reduce search time


#1

I have big search index, i want to narrow deep by filter to reduce search time: so first filter data to search by user project, and then search.
Now i do search by all data of all user projects - this is very slow.
From docs i found:

s = Search()
s = s.filter('terms', tags=['search', 'python'])

http://elasticsearch-dsl.readthedocs.io/en/latest/search_dsl.html

and i do this in my code ("project" is a field from search_indexes.py)
but the following code doesn't find anything (without filter all works)

        q = Q('bool',
            #must=[Q('match', text='BBQ')],
            should=eval(i),  #[Q(...), Q(...)],
            minimum_should_match='1', 
            _name=name_query  
        )
        s = Search(using=client, index="haystack")
        s = s.filter('terms', project=[project_id])
        s = s.query(q).query(~Q("match", text=minus_words))
    
        s.aggs.bucket('per_tag', 'terms', field='project') \
            .metric('max_lines', 'max', field='lines')        
        
        s = s.highlight('text', fragment_size=50)
        s = s[0:1000]
        
        response = s.execute()

(system) #2

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.