[英]ElasticSearch query doesn't work
I have the following document: 我有以下文件:
{
"_index": "taskmanager",
"_type": "tasks",
"_id": "AVn4vhIKiS68kYrc2Xp0",
"_score": 0.8784157,
"_source": {
"Id": 2,
"Title": "Hello World",
"Description": "Description example",
"PublishDate": "2017-01-29T15:06:04",
"IsCompleted": true
}
I can got the list of documents executing the query: 我可以获得执行查询的文档列表:
var hits = elasticClient.Search<Task>(s => s);
But I got nothing trying to get documents which contains 'world'. 但是我什么也不想得到包含“世界”的文档。
var hits = elasticClient.Search<DalTask>(s => s
.Type("tasks")
.Query(q => q
.Match(m => m
.Field(p => p.Title).Query("world")
)
)
).Hits;
Where is my mistake? 我的错误在哪里? Ps My index set to default "taskmanager".
Ps我的索引设置为默认的“任务管理器”。
By default, NEST camel cases C# POCO property names when serializing them to Elasticsearch document field names in the request, so 默认情况下,NEST骆驼案例将C#POCO属性名称序列化为请求中的Elasticsearch文档字段名称时,因此
.Field(p => p.Title)
becomes 变成
"title"
in the request. 在请求中。 Looking at the
_source
in the response you have posted, it looks like your field names are Pascal-cased, hence the casing of field name in the search request is different and will not match. 在您发布的响应中查看
_source
,您的字段名称看起来用Pascal大小写,因此搜索请求中字段名称的大小写是不同的并且不匹配。
You can change how NEST serializes C# POCO property names by changing .DefaultFieldNameInferrer(Func<string, string>)
on ConnectionSettings
您可以通过更改
ConnectionSettings
上的.DefaultFieldNameInferrer(Func<string, string>)
来更改NEST序列化C#POCO属性名称的方式
var pool = new SingleNodeConnectionPool(new Uri("http://localhost:9200"));
var connectionSettings = new ConnectionSettings(pool)
// serialize POCO property names verbatim
.DefaultFieldNameInferrer(s => s);
var client = new ElasticClient(connectionSettings);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.