本文整理汇总了Python中pyes.query.MatchAllQuery.search方法的典型用法代码示例。如果您正苦于以下问题:Python MatchAllQuery.search方法的具体用法?Python MatchAllQuery.search怎么用?Python MatchAllQuery.search使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyes.query.MatchAllQuery
的用法示例。
在下文中一共展示了MatchAllQuery.search方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_terms_facet_filter
# 需要导入模块: from pyes.query import MatchAllQuery [as 别名]
# 或者: from pyes.query.MatchAllQuery import search [as 别名]
def test_terms_facet_filter(self):
q = MatchAllQuery()
q = FilteredQuery(q, TermFilter("tag", "foo"))
q = q.search()
q.facet.add_term_facet("tag")
resultset = self.conn.search(query=q, indices=self.index_name, doc_types=[self.document_type])
self.assertEquals(resultset.total, 2)
self.assertEquals(resultset.facets["tag"]["terms"], [{u"count": 2, u"term": u"foo"}])
self.assertEquals(resultset.facets.tag.terms, [{u"count": 2, u"term": u"foo"}])
q2 = MatchAllQuery()
q2 = FilteredQuery(q2, TermFilter("tag", "foo"))
q2 = q2.search()
q2.facet.add_term_facet("tag")
q3 = MatchAllQuery()
q3 = FilteredQuery(q3, TermFilter("tag", "foo"))
q3 = q3.search()
q3.facet.add_term_facet("tag")
self.assertEquals(q2, q3)
q4 = MatchAllQuery()
q4 = FilteredQuery(q4, TermFilter("tag", "foo"))
q4 = q4.search()
q4.facet.add_term_facet("bag")
self.assertNotEquals(q3, q4)
示例2: dump
# 需要导入模块: from pyes.query import MatchAllQuery [as 别名]
# 或者: from pyes.query.MatchAllQuery import search [as 别名]
def dump(start,end,backupdir,eshost):
conn = ES(eshost)
out = file('/tmp/out.json','w')
_type = 'habakkuk'
q = MatchAllQuery()
q = FilteredQuery(q, RangeFilter(qrange=ESRange('created_at_date',start,end,include_upper=False)))
q = q.search()
# print json.dumps(json.loads(q.to_search_json()),indent=2)
resultset = conn.search(query=q,indices=_type+"-*", doc_types=[_type], scan=True)
cnt=0
if not resultset.total:
sys.stderr.write("no data for %s - %s\n"%(start,end))
return
try:
sys.stderr.write("Will write %d lines to %s\n"%(resultset.total, out.name))
while True:
r = resultset.next()
cnt+=1
out.write(json.dumps(r)+'\n')
except StopIteration:
pass
out.close()
# gzip
ext = datetime.strftime(start,'%Y-%m-%d')
backup = os.path.join(backupdir,"habakkuk-%s.json.gz"%ext)
f_in = open(out.name,'rb')
f_out = gzip.open(backup,'wb')
f_out.writelines(f_in)
f_out.close()
f_out.close()
sys.stderr.write("Created %s\n"%backup)
示例3: term_facet
# 需要导入模块: from pyes.query import MatchAllQuery [as 别名]
# 或者: from pyes.query.MatchAllQuery import search [as 别名]
def term_facet(host='localhost:9200',
terms=['bibleverse'],
_type='habakkuk',
date_filter=[],
size=10):
ret = []
conn = ES(host)
q = MatchAllQuery()
if date_filter:
start,end = date_filter
q = FilteredQuery(q, RangeFilter(qrange=ESRange('created_at_date',start,end,include_upper=False)))
q = q.search(size=0)
for term in terms:
q.facet.add_term_facet(term,order='count',size=size)
print json.dumps(json.loads(q.to_search_json()),indent=2)
resultset = conn.search(query=q, indices=_type+'-*', doc_types=[_type])
for facet in resultset.facets:
print "Total",facet,resultset.facets[facet]['total']
for row in resultset.facets[facet]['terms']:
print "\t",row['term'],row['count']
ret.append((facet,row['term']))
return ret
示例4: facets
# 需要导入模块: from pyes.query import MatchAllQuery [as 别名]
# 或者: from pyes.query.MatchAllQuery import search [as 别名]
def facets(host='localhost:9200',
facet_terms=['bibleverse'],
_type='habakkuk',
date_filter=[],
size=10):
ret = {}
conn = ES(host)
q = MatchAllQuery()
if date_filter:
start,end = date_filter
q = FilteredQuery(q, RangeFilter(qrange=ESRange('created_at_date',
start.isoformat(),
end.isoformat(),
include_upper=False)))
q = q.search(size=0)
for term in facet_terms:
q.facet.add_term_facet(term,order='count',size=size)
es_logger.info(q.serialize())
resultset = conn.search(query=q, indices=_type+'-*', doc_types=[_type])
for facet in resultset.facets:
ret[facet] = []
for row in resultset.facets[facet]['terms']:
ret[facet].append({"value":row['term'],"count":row['count']})
logger.debug("facets return|'%s'"%json.dumps(ret))
return ret
示例5: test_terms_facet
# 需要导入模块: from pyes.query import MatchAllQuery [as 别名]
# 或者: from pyes.query.MatchAllQuery import search [as 别名]
def test_terms_facet(self):
q = MatchAllQuery()
q = q.search()
q.facet.add_term_facet('tag')
result = self.conn.search(query=q, indexes=["test-index"], doc_types=["test-type"])
self.assertEquals(result['hits']['total'], 3)
self.assertEquals(result['facets']['tag']['terms'], [{u'count': 2, u'term': u'foo'},
{u'count': 1, u'term': u'bar'}])
示例6: test_terms_facet
# 需要导入模块: from pyes.query import MatchAllQuery [as 别名]
# 或者: from pyes.query.MatchAllQuery import search [as 别名]
def test_terms_facet(self):
q = MatchAllQuery()
q = q.search()
q.facet.add_term_facet('tag')
resultset = self.conn.search(query=q, indices=self.index_name, doc_types=[self.document_type])
self.assertEquals(resultset.total, 3)
self.assertEquals(resultset.facets.tag.terms, [{u'count': 2, u'term': u'foo'},
{u'count': 1, u'term': u'bar'}])
示例7: test_nested_agg
# 需要导入模块: from pyes.query import MatchAllQuery [as 别名]
# 或者: from pyes.query.MatchAllQuery import search [as 别名]
def test_nested_agg(self):
q = MatchAllQuery()
q = q.search()
nested = NestedAgg(name="nested", path="resellers")
q.agg.add(nested)
resultset = self.conn.search(query=q, indices=self.index_name, doc_types=[self.document_type])
self.assertEqual(resultset.total, 3)
self.assertEqual(resultset.aggs.nested, {u"doc_count": 4})
示例8: test_terms_facet_filter
# 需要导入模块: from pyes.query import MatchAllQuery [as 别名]
# 或者: from pyes.query.MatchAllQuery import search [as 别名]
def test_terms_facet_filter(self):
q = MatchAllQuery()
q = FilteredQuery(q, TermFilter('tag', 'foo'))
q = q.search()
q.facet.add_term_facet('tag')
resultset = self.conn.search(query=q, indices=["test-index"], doc_types=["test-type"])
self.assertEquals(resultset.total, 2)
self.assertEquals(resultset.facets['tag']['terms'], [{u'count': 2, u'term': u'foo'}])
示例9: test_max_agg
# 需要导入模块: from pyes.query import MatchAllQuery [as 别名]
# 或者: from pyes.query.MatchAllQuery import search [as 别名]
def test_max_agg(self):
q = MatchAllQuery()
q = q.search()
max_agg = MaxAgg(name="max", field="position")
q.agg.add(max_agg)
resultset = self.conn.search(query=q, indices=self.index_name, doc_types=[self.document_type])
self.assertEqual(resultset.total, 3)
self.assertEqual(resultset.aggs.max, {u"value": 3})
示例10: test_missing_agg
# 需要导入模块: from pyes.query import MatchAllQuery [as 别名]
# 或者: from pyes.query.MatchAllQuery import search [as 别名]
def test_missing_agg(self):
q = MatchAllQuery()
q = q.search()
missing = MissingAgg(name="missing", field="integer")
q.agg.add(missing)
resultset = self.conn.search(query=q, indices=self.index_name, doc_types=[self.document_type])
self.assertEqual(resultset.total, 3)
self.assertEqual(resultset.aggs.missing, {u"doc_count": 1})
示例11: test_min_agg
# 需要导入模块: from pyes.query import MatchAllQuery [as 别名]
# 或者: from pyes.query.MatchAllQuery import search [as 别名]
def test_min_agg(self):
q = MatchAllQuery()
q = q.search()
missing = MinAgg(name="min", field="position")
q.agg.add(missing)
resultset = self.conn.search(query=q, indices=self.index_name, doc_types=[self.document_type])
self.assertEqual(resultset.total, 3)
self.assertEqual(resultset.aggs.min, {u'value': 1})
示例12: get_top_authors
# 需要导入模块: from pyes.query import MatchAllQuery [as 别名]
# 或者: from pyes.query.MatchAllQuery import search [as 别名]
def get_top_authors():
q = MatchAllQuery()
q = q.search()
q.facet.add_term_facet('author')
es = get_connection()
facets = es.search(q, ELASTICSEARCH_INDEX, 'post').facets
authors = []
for term in facets['author']['terms']:
authors.append(get_author(id=term['term']))
return authors
示例13: test_terms_facet
# 需要导入模块: from pyes.query import MatchAllQuery [as 别名]
# 或者: from pyes.query.MatchAllQuery import search [as 别名]
def test_terms_facet(self):
q = MatchAllQuery()
q = q.search()
q.facet.add_term_facet("tag")
resultset = self.conn.search(query=q, indices=self.index_name, doc_types=[self.document_type])
self.assertEquals(resultset.total, 3)
self.assertEquals(resultset.facets.tag.terms, [{u"count": 2, u"term": u"foo"}, {u"count": 1, u"term": u"bar"}])
q2 = MatchAllQuery()
q2 = q2.search()
q2.facet.add_term_facet("tag")
q3 = MatchAllQuery()
q3 = q3.search()
q3.facet.add_term_facet("tag")
self.assertEquals(q2, q3)
q4 = MatchAllQuery()
q4 = q4.search()
q4.facet.add_term_facet("bag")
self.assertNotEquals(q2, q4)
示例14: test_reverse_nested_agg
# 需要导入模块: from pyes.query import MatchAllQuery [as 别名]
# 或者: from pyes.query.MatchAllQuery import search [as 别名]
def test_reverse_nested_agg(self):
q = MatchAllQuery()
q = q.search()
reverse_nested = ReverseNestedAgg(name="reverse", field="id")
nested = NestedAgg(name="nested", path="resellers", sub_aggs=[reverse_nested])
q.agg.add(nested)
resultset = self.conn.search(query=q, indices=self.index_name, doc_types=[self.document_type])
self.assertEqual(resultset.total, 3)
self.assertEqual(resultset.aggs.nested["doc_count"], 4)
self.assertEqual(resultset.aggs.nested.reverse, {u"doc_count": 2})
示例15: test_date_facet_filter
# 需要导入模块: from pyes.query import MatchAllQuery [as 别名]
# 或者: from pyes.query.MatchAllQuery import search [as 别名]
def test_date_facet_filter(self):
q = MatchAllQuery()
q = FilteredQuery(q, RangeFilter(qrange=ESRange('date',
datetime.date(2011, 4, 1),
datetime.date(2011, 5, 1),
include_upper=False)))
q = q.search()
q.facet.facets.append(DateHistogramFacet('date_facet',
field='date',
interval='month'))
resultset = self.conn.search(query=q, indices=self.index_name, doc_types=[self.document_type])
self.assertEquals(resultset.total, 2)
self.assertEquals(resultset.facets['date_facet']['entries'], [{u'count': 2, u'time': 1301616000000}])