【发布时间】:2017-12-27 11:50:41
【问题描述】:
我在 product 和 account 索引中有两种类型 producttype 和 accounttype,我需要构建一个搜索查询以同时命中它们。
现在我得到了以下查询:
var searchResponse = elasticClient.Search<object>(s => s
.Index(indices)
.Type(Types.Type(typeof(ProductType), typeof(accountType)))
.Query(q => q
q.Nested(n => n
.Path(Infer.Field<ProductType>(ff => ff.Keywords))
.Query(nq => nq
.Match(t => t
.Field(Infer.Field<ProductType>(ff => ff.Keywords.First().Keyword))
.Query(query)
)
||
nq.Term(Infer.Field<ProductType>(ff => ff.Keywords.First().Keyword.Suffix("keyword")), query)
)
)
&&
+q.Term("_type", "producttype")
||
q.MultiMatch(m => m
.Fields(f => f
.Field(Infer.Field<accountType>(ff => ff.AccountName, 1.5))
.Field(Infer.Field<accountType>(ff => ff.Description, 0.8))
)
.Operator(Operator.Or)
.Query(query)
) &&
+q.Term("_type", "accounttype")
)
);
当我运行此查询时,它不起作用,因为在 accounttype 中找不到关键字嵌套对象(但在我的情况下,我按 _type 过滤,所以它应该可以工作)。
那么当我在一个索引中嵌套对象时,如何按_index/_type 进行过滤?
【问题讨论】:
标签: nest