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


Python Query.nested方法代码示例

本文整理汇总了Python中elastic.query.Query.nested方法的典型用法代码示例。如果您正苦于以下问题:Python Query.nested方法的具体用法?Python Query.nested怎么用?Python Query.nested使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在elastic.query.Query的用法示例。


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

示例1: fetch_overlapping_features

# 需要导入模块: from elastic.query import Query [as 别名]
# 或者: from elastic.query.Query import nested [as 别名]
    def fetch_overlapping_features(cls, build, seqid, start, end, idx=None, idx_type=None, disease_id=None):
        ''' function to create fetch overlapping features for a given stretch of region
            the build info is stored as nested document..so nested query is build
        @type  build: string
        @param build: build info eg: 'GRCh38'
        @type  seqid: string
        @param seqid: chromosome number
        @type  start:  string
        @param start: region start
        @type  end:  string
        @param end: region end
        @type  idx: string
        @param idx: name of the index
        @type  idx_type: string
        @param idx_type: name of the idx type, each criteria is an index type
        @type  disease_id:  string
        @param disease_id: disease code
        '''
        nbuild = build
        start_range = start
        end_range = end

        bool_range = BoolQuery()
        bool_range.must(RangeQuery("build_info.start", lte=start_range)) \
                  .must(RangeQuery("build_info.end", gte=end_range))

        or_filter = OrFilter(RangeQuery("build_info.start", gte=start_range, lte=end_range))

        or_filter.extend(RangeQuery("build_info.end", gte=start_range, lte=end_range)) \
                 .extend(bool_range)

        bool_query = BoolQuery()

        if disease_id:
            qnested_buildinfo = Query.nested('build_info', bool_query)
            bool_query = BoolQuery()
            bool_query.must(Query.term("disease", disease_id.lower())).must(qnested_buildinfo)
            qnested = ElasticQuery(bool_query, sources=['build_info.*',
                                                        'disease_locus',
                                                        'disease',
                                                        'chr_band',
                                                        'species'])

        else:
            bool_query.must(Query.term("build_info.build", nbuild)) \
                  .must(Query.term("build_info.seqid", seqid)) \
                  .filter(or_filter)

            qnested = ElasticQuery(Query.nested('build_info', bool_query), sources=['build_info.*',
                                                                                    'disease_locus',
                                                                                    'disease',
                                                                                    'chr_band',
                                                                                    'species'])

        elastic = Search(qnested, idx=idx, idx_type=idx_type)
        res = elastic.search()
        return res.docs
开发者ID:D-I-L,项目名称:django-criteria,代码行数:59,代码来源:criteria.py

示例2: get_overlapping_hits

# 需要导入模块: from elastic.query import Query [as 别名]
# 或者: from elastic.query.Query import nested [as 别名]
    def get_overlapping_hits(self, build, seqid, start, end):
        query_bool = BoolQuery(must_arr=[RangeQuery("build_info.start", lte=start),
                                         RangeQuery("build_info.end", gte=end)])
        or_filter = OrFilter(RangeQuery("build_info.start", gte=start, lte=end))
        or_filter.extend(RangeQuery("build_info.end", gte=start, lte=end)) \
                 .extend(query_bool)
        range_query = FilteredQuery(BoolQuery(must_arr=[Query.term("build_info.seqid", seqid),
                                                        Query.term("build_info.build", build)]),
                                    or_filter)

        query = ElasticQuery.filtered_bool(
            Query.nested("build_info", range_query),
            BoolQuery(must_arr=[RangeQuery("tier", lte=2)]),
            # sources=["disease", "marker", "chr_band", "tier", "build_info", "disease_locus"]
            )
        elastic = Search(search_query=query, idx=ElasticSettings.idx('REGION', 'STUDY_HITS'))
        return elastic.search().docs
开发者ID:D-I-L,项目名称:pydgin,代码行数:19,代码来源:document.py

示例3: print

# 需要导入模块: from elastic.query import Query [as 别名]
# 或者: from elastic.query.Query import nested [as 别名]
    }
    #    "suggest": {"input": [disease+" "+regionName, regionName], "weight": weight}
    resp = requests.put(ElasticSettings.url()+'/' + idx+'/disease_locus/'+locus_id, data=json.dumps(data))
    if resp.status_code != 201:
        print(str(resp.content))
        print("Problem loading "+getattr(doc, "disease")+" "+regionName)
    else:
        print("Loaded "+locus_id+" - "+regionName)

Search.index_refresh(idx)
diseases_by_seqid = Agg('diseases_by_seqid', 'terms', {"size": 0, "field": "disease"})
disease_hits = Agg('disease_hits', 'reverse_nested', {}, sub_agg=diseases_by_seqid)
seq_hits = Agg('seq_hits', 'terms', {'field': 'build_info.seqid', 'size': 0}, sub_agg=disease_hits)
build_info = Agg('build_info', 'nested', {"path": 'build_info'}, sub_agg=[seq_hits])

qnested = ElasticQuery(Query.nested('build_info', Query.term("build_info.build", build)))
elastic = Search(qnested, idx=idx, aggs=Aggs(build_info), search_type='count')
resultObj = elastic.search()
resultAggs = resultObj.aggs
seq_hits = getattr(resultAggs['build_info'], 'seq_hits')['buckets']

for chr_bucket in seq_hits:
    seqid = chr_bucket['key'].upper()

    for disease_bucket in chr_bucket['disease_hits']['diseases_by_seqid']['buckets']:
        # print(disease_bucket)
        disease_code = disease_bucket['key']
        print("\n"+str(seqid)+" - "+disease_code)
        query2 = ElasticQuery.filtered_bool(
            Query.nested("build_info", BoolQuery(
                must_arr=[Query.term("build_info.seqid", chr_bucket['key']), Query.term("build_info.build", build)])),
开发者ID:D-I-L,项目名称:django-data-pipeline,代码行数:33,代码来源:hits_to_diseaseLoci.py


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