在Elasticsearch上使用C#NEST API:
var searchResults = client.Search<Product>(s => s
.Index(Constants.ElasticSearchIndex)
.Query(q => q
.Raw(jsonRequest)
)
);
该查询应该在/ sc_all /索引上运行,但是在/ sc_all / product /索引上运行(该索引不存在-由于T = product,因此由于搜索而添加了/ product /)。
如果我这样做,将/ product /替换为常量的值,即/ sc_all / product / => / sc_all / constant_value /:
var searchResults = client.Search<Product>(s => s
.Index(Constants.ElasticSearchIndex)
.Type(Constants.ElasticSearchType)
.Query(q => q
.Raw(jsonRequest)
)
);
如果我只想查询/ sc_all /而不是其他内容,该怎么办?
谢谢!
杰森要求:
“ {\” filtered \“:{\” query \“:{\” match_all \“:{}},\” filter \“:{\” nested \“:{\” path \“:\” products \ “,\” filter \“:{\”嵌套\“:{\”路径\“:\” products.da \“,\” filter \“:{\” bool \“:{\”必须\“: [{\“ query \”:{\“ query_string \”:{\“ default_field \”:\“ products.da.content \”,\“ query \”:\“ kildemoes \”}}}}}}}} }}}}},\“来自\”:0,\“大小\”:100“
您只需要指定即可跨所有类型运行 .AllTypes()
var jsonRequest = "{ \"match_all\": {} }";
var searchResults = client.Search<Product>(s => s
.Index(Constants.ElasticSearchIndex)
.AllTypes()
.Query(q => q
.Raw(jsonRequest)
)
);
这将生成以下请求
POST http://localhost:9200/sc_all/_search
{
"query": { "match_all": {} }
}
请记住,所有返回的文档都将尝试反序列化为的实例,Product
因此,如果您要针对多种不同的类型,则可能要使用通用的基本类型,或者dynamic
此外,还要利用协变搜索结果。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句