def get_es_index_doc_count(cls, full_index_version_name, **kwargs): s = Search(index=full_index_version_name, using=es_client, **kwargs) try: return s.query(ESQ('match_all')).count() except TransportError as ex: if ex.status_code == 404: return 0 else: raise ex
def query(self, search, query): s = search _searches = query.get('searches', None) _options = query.get('options', None) if not _searches: return s # elasticsearch 'must' queries _musts = [] _must_nots = [] for key, value in _searches.iteritems(): # not particularly nice - maybe there is a better way to build queries here # 'q' - the main search query if key == 'q': if _options.get('fuzzy', True): _q = ESQ('match', autocomplete={'query': ' '.join(value), 'operator': 'and', 'fuzziness': 'AUTO'}) else: _q = ESQ('match', autocomplete={'query': ' '.join(value), 'operator': 'and'}) _musts.append( _q, ) # 'id' - for pre-filtered querysets elif key == 'ids': _musts.append( ESQ('terms', _id=value) ) # 'tags' - for 'intersection-style' tagcloud elif key == 'tags': for tag in value: _musts.append( ESQ('term', tags=tag) ) else: for v in value: if not v[0:1] == '-': #print('must', v) _musts.append( ESQ('term', **{key: v}) ) else: #print('must not', v[1:]) _must_nots.append( ESQ('term', **{key: v[1:]}) ) if _musts or _must_nots: s.query = ESQ('bool', must=_musts, must_not=_must_nots) return s
def clear(self): """ Remove all of the documents in this index. """ self.search().query(ESQ('match_all')).delete()
def get_num_docs(self): return self.search().query(ESQ('match_all')).count()
def instance(self): params = self.value.split(self.expr) key = str(params[0]).strip() value = str(params[1]).strip() return ESQ(self.name, **{key: {self.symbol: value}})
def instance(self): params = self.value.split('==') key = str(params[0]).strip() value = str(params[1]).strip() value = map(lambda x: x.strip(' "'), value.strip('[]').split(',')) return ESQ(self.name, **{key: value})