当前位置: 首页>>代码示例>>Python>>正文


Python MatchAllQuery.search方法代码示例

本文整理汇总了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)
开发者ID:Naeka,项目名称:pyes,代码行数:27,代码来源:test_facets.py

示例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)
开发者ID:gregors,项目名称:habakkuk-alpha,代码行数:37,代码来源:dump_data_for_date.py

示例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
开发者ID:gregors,项目名称:habakkuk-alpha,代码行数:28,代码来源:bible_facet.py

示例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
开发者ID:telvis07,项目名称:habakkuk_web,代码行数:31,代码来源:bible_facet.py

示例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'}])
开发者ID:AndryulE,项目名称:kitsune,代码行数:10,代码来源:facets.py

示例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'}])
开发者ID:EnTeQuAk,项目名称:pyes,代码行数:10,代码来源:test_facets.py

示例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})
开发者ID:idon2020,项目名称:pyes,代码行数:10,代码来源:test_aggs.py

示例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'}])
开发者ID:akheron,项目名称:pyes,代码行数:10,代码来源:test_facets.py

示例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})
开发者ID:idon2020,项目名称:pyes,代码行数:11,代码来源:test_aggs.py

示例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})
开发者ID:idon2020,项目名称:pyes,代码行数:11,代码来源:test_aggs.py

示例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})
开发者ID:julianhille,项目名称:pyes,代码行数:11,代码来源:test_aggs.py

示例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
开发者ID:adamzagorski,项目名称:django-elasticsearch-tutorial,代码行数:12,代码来源:models.py

示例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)
开发者ID:Naeka,项目名称:pyes,代码行数:22,代码来源:test_facets.py

示例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})
开发者ID:idon2020,项目名称:pyes,代码行数:14,代码来源:test_aggs.py

示例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}])
开发者ID:akkumar,项目名称:pyes,代码行数:15,代码来源:test_facets.py


注:本文中的pyes.query.MatchAllQuery.search方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。