只要找出关于nest的事。我已经在Elastic Search中插入了一些文档。现在,我想根据我的类型subcriberId搜索数据。我确实运行了curl,它工作得很好。但是当我尝试使用nest时,没有找到结果。
我的卷发很管用:
http://localhost:9200/20160902/_search?q=subscribeId:aca0ca1a-c96a-4534-ab0e-f844b81499b7
我的嵌套代码:
var local = new Uri("http://localhost:9200");
var settings = new ConnectionSettings(local);
var elastic = new ElasticClient(settings);
var response = elastic.Search<IntegrationLog>(s => s
.Index(DateTime.Now.ToString("yyyyMMdd"))
.Type("integrationlog")
.Query(q => q
.Term(p => p.SubscribeId, new Guid("aca0ca1a-c96a-4534-ab0e-f844b81499b7"))
)
);谁能指出我做错了什么?
发布于 2016-09-03 07:54:33
curl请求和嵌套查询之间的一个关键区别是前者使用的是query_string查询,而后者使用的是term查询。query_string查询输入会在查询时进行分析,而term查询输入则不会,这取决于subscribeId的分析方式(或不分析方式),您可能会看到不同的结果。此外,curl请求将跨索引20160902中的所有文档类型进行搜索。
在嵌套中执行与curl请求完全相同的查询
void Main()
{
var pool = new SingleNodeConnectionPool(new Uri("http://localhost:9200"));
var connectionSettings = new ConnectionSettings(pool)
// set up NEST with the convention to use the type name
// "integrationlog" for the IntegrationLog
// POCO type
.InferMappingFor<IntegrationLog>(m => m
.TypeName("integrationlog")
);
var client = new ElasticClient(connectionSettings);
var searchResponse = client.Search<IntegrationLog>(s => s
.Index("20160902")
// search across all types. Note that documents found
// will be deserialized into instances of the
// IntegrationLog type
.AllTypes()
.Query(q => q
// use query_string query
.QueryString(qs => qs
.Fields(f => f
.Field(ff => ff.SubscribeId)
)
.Query("aca0ca1a-c96a-4534-ab0e-f844b81499b7")
)
)
);
}
public class IntegrationLog
{
public Guid SubscribeId { get; set; }
}这就产生了
POST http://localhost:9200/20160902/_search
{
"query": {
"query_string": {
"query": "aca0ca1a-c96a-4534-ab0e-f844b81499b7",
"fields": [
"subscribeId"
]
}
}
}这将在请求正文中指定query_string查询,这类似于使用q查询字符串参数来指定查询。
https://stackoverflow.com/questions/39289691
复制相似问题