def query_string(search_phrase): res = es.search(index='online_library', body={ 'from': 0, 'size': 4, 'query': { 'query_string': { 'query': '*{}*'.format(search_phrase), 'fields': ['title^5', 'persons^5', 'genre'] } } }) return res
def wildcard_es(search_phrase): result = [] fields = get_fields_by_boost() es_res = es.search(index='online_library', body={ 'from': 0, 'size': 4, 'query': { 'wildcard': { 'title': { 'value': 'my*s', 'boost': 1.0, 'rewrite': 'constant_score' } } } }) return es_res
def search_phrase(data): result = [] fields = get_fields_by_boost() es_res = es.search(index='online_library', body={ 'from': data.get('from'), 'size': data.get('size'), 'query': { 'query_string': { 'query': '*{}*'.format(data.get('search_phrase')), 'fields': fields, 'rewrite': 'constant_score' } } }) # # es_res = es.search(index='online_library', body={'from': 0, 'size': 4, 'query': { # 'multi_match': {'query': search_phrase, 'type': 'most_fields', 'fields': fields, 'fuzziness': 'AUTO'}}}) hits = es_res.get('hits', None) count = 0 if hits is not None: count = hits.get('total') print('count ==> {}'.format(count)) rs = hits.get('hits') print('hits ==> {} ,\n\n\n\n\n\n len_hits = {}\n\n\n\n\n\n'.format( rs, len(rs))) if len(rs) > 0: for item in rs: result.append(item.get('_id')) return result
def search_by_book_id(book_id): body = {'query': {'match': {'book_id': book_id}}} res = es.search(index='online_library', body=body) return res