• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python query.MatchAllQuery类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pyes.query.MatchAllQuery的典型用法代码示例。如果您正苦于以下问题:Python MatchAllQuery类的具体用法?Python MatchAllQuery怎么用?Python MatchAllQuery使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了MatchAllQuery类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_facet_filter_is_serialized_correctly

 def test_facet_filter_is_serialized_correctly(self):
     query = MatchAllQuery().search(size=0)
     query.facet.add(
         TermFacet(field="topic", facet_filter=BoolFilter(must_not=TermQuery(field="reviewed", value=True)))
     )
     serialized = query.serialize()
     self.assertTrue(serialized["facets"]["topic"]["facet_filter"]["bool"])
开发者ID:Naeka,项目名称:pyes,代码行数:7,代码来源:test_facets.py


示例2: facets

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,代码行数:29,代码来源:bible_facet.py


示例3: term_facet

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,代码行数:26,代码来源:bible_facet.py


示例4: dump

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,代码行数:35,代码来源:dump_data_for_date.py


示例5: test_terms_facet_filter

 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,代码行数:8,代码来源:test_facets.py


示例6: test_terms_facet

 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,代码行数:8,代码来源:test_facets.py


示例7: test_terms_facet

 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,代码行数:8,代码来源:facets.py


示例8: test_nested_agg

 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,代码行数:8,代码来源:test_aggs.py


示例9: test_min_agg

    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,代码行数:9,代码来源:test_aggs.py


示例10: test_max_agg

    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,代码行数:9,代码来源:test_aggs.py


示例11: test_missing_agg

    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,代码行数:9,代码来源:test_aggs.py


示例12: get_top_authors

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,代码行数:10,代码来源:models.py


示例13: test_reverse_nested_agg

    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,代码行数:12,代码来源:test_aggs.py


示例14: test_date_facet_filter

 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,代码行数:13,代码来源:test_facets.py


示例15: test_date_facet_filter

 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:Naeka,项目名称:pyes,代码行数:13,代码来源:test_facets.py


示例16: test_date_facet

 def test_date_facet(self):
     q = MatchAllQuery()
     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, 3)
     self.assertEquals(resultset.facets.date_facet.entries, [{u'count': 2, u'time': 1301616000000},
             {u'count': 1, u'time': 1304208000000}])
     self.assertEquals(datetime.datetime.utcfromtimestamp(1301616000000 / 1000.).date(),
         datetime.date(2011, 04, 01))
     self.assertEquals(datetime.datetime.utcfromtimestamp(1304208000000 / 1000.).date(),
         datetime.date(2011, 05, 01))
开发者ID:akkumar,项目名称:pyes,代码行数:14,代码来源:test_facets.py


示例17: test_date_facet

 def test_date_facet(self):
     q = MatchAllQuery()
     q = q.search()
     q.facet.facets.append(DateHistogramFacet('date_facet',
                                              field='date',
                                              interval='month'))
     result = self.conn.search(query=q, indexes=["test-index"], doc_types=["test-type"])
     self.assertEquals(result['hits']['total'], 3)
     self.assertEquals(result['facets']['date_facet']['entries'], [{u'count': 2, u'time': 1301616000000},
                                                                   {u'count': 1, u'time': 1304208000000}])
     self.assertEquals(datetime.datetime.fromtimestamp(1301616000000/1000.).date(),
                       datetime.date(2011, 04, 01))
     self.assertEquals(datetime.datetime.fromtimestamp(1304208000000/1000.).date(),
                       datetime.date(2011, 05, 01))
开发者ID:AndryulE,项目名称:kitsune,代码行数:14,代码来源:facets.py


示例18: dump_topics

def dump_topics(backupdir,
                eshost,
                _type,
                indices="topics-all"):
    conn = ES(eshost)
    out = file('/tmp/out.json','w')
    q = MatchAllQuery()
    q = q.search()

    resultset = conn.search(query=q,indices=indices, doc_types=[_type], scan=True)
    cnt=0
    if not resultset.total:
        sys.stderr.write("no data\n")
        return

    try:
        sys.stderr.write("Will write %d lines to %s\n"%(resultset.total, out.name))
        while True:
            r = resultset.next()
            r['_id'] = r._meta.id
            cnt+=1
            out.write(json.dumps(r)+'\n')
    except StopIteration:
        pass

    out.close()

    # gzip
    backup = os.path.join(backupdir,"topics.{}.json.gz".format(_type))

    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:evethandar,项目名称:habakkuk,代码行数:36,代码来源:dump_data_for_date.py


示例19: test_terms_facet

    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,代码行数:20,代码来源:test_facets.py


示例20: test_terms_facet_filter

    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:akkumar,项目名称:pyes,代码行数:25,代码来源:test_facets.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python search.SearchConnection类代码示例发布时间:2022-05-25
下一篇:
Python pyes.ES类代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap