ElasticSearch2.4.6 + Spring-data filter功能不正常
Elasticsearch | 作者 linfujian | 发布于2018年09月07日 | 阅读数:3461
我有一个document如下图所示:
我的代码过滤逻辑如下:
var为c.313A>G
应该能检索到第一条document的,但是就是检索不到,请大神赐教
{
"_index" : "var_pmid",
"_type" : "var_pmid_list",
"_id" : "79462",
"_score" : 10.701287,
"_source" : {
"mutation_id" : "",
"pmid" : "25996639",
"chr_id" : "chr5:g.36958288A>G",
"cdna" : "c.313A>G",
"gene" : "",
"kinds" : "",
"nlp" : "",
"paper" : "",
"resource" : "",
"snp" : "rs376768802",
"snpeff_ann" : "c.-31-28915T>A",
"var" : "",
"var_s" : "p.N105D",
"issn" : "1098-3600",
"pubDate" : "2016-10-20",
"IF" : 8.229
}
我的代码过滤逻辑如下:
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
boolQueryBuilder
.should(QueryBuilders.matchPhraseQuery("paper", var))
.should(QueryBuilders.matchPhraseQuery("snpeff_ann", var))
.should(QueryBuilders.matchPhraseQuery("chr_id", var))
.should(QueryBuilders.matchPhraseQuery("snp", var))
.should(QueryBuilders.matchPhraseQuery("var_s", var))
.should(QueryBuilders.matchPhraseQuery("var", var))
.should(QueryBuilders.matchPhraseQuery("mutation_id", var))
.should(QueryBuilders.matchPhraseQuery("cdna", var))
.should(QueryBuilders.matchPhraseQuery("clinvarID", var));
//加过滤条件
BoolQueryBuilder filterBuilder = QueryBuilders.boolQuery();
String ifStr = {"5","10"};
filterBuilder
.filter(QueryBuilders.rangeQuery("IF").gte(Float.parseFloat(ifStr[0])).lte(Float.parseFloat(ifStr[1])));
SearchQuery searchQuery2 = new NativeSearchQueryBuilder()
.withQuery(QueryBuilders.filteredQuery(boolQueryBuilder, filterBuilder))
.withIndices("var_pmid")
.withTypes("var_pmid_list")
.build();
List<Var2PmidEntity> entities2 = esUtil.queryAll(searchQuery2, Var2PmidEntity.class);
//如下是queryAll方法
public <T> List<T> queryAll(SearchQuery searchQuery, Class<T> T) {
String scrollId = scan(searchQuery, 5000l, false);
List<T> entities = new ArrayList<>();
boolean hasRecords = true;
while (hasRecords) {
SearchResponse searchResponse = getClient().prepareSearchScroll(scrollId).
setScroll(new TimeValue(5000l)).execute().actionGet();
Page<T> page = getResultsMapper().mapResults(searchResponse, T, null);
if(page.hasContent()) {
entities.addAll(page.getContent());
scrollId = searchResponse.getScrollId();
} else {
hasRecords = false;
}
}
clearScroll(scrollId);
return entities;
}
var为c.313A>G
应该能检索到第一条document的,但是就是检索不到,请大神赐教
3 个回复
linfujian
赞同来自:
附件一句:document的IF是后来更新添加的新字段,之前保存的是String类型,后来update成了float类型
linfujian
赞同来自:
linfujian
赞同来自: