这是我的客户代码:
设置
var defaultSettings = new ConnectionSettings(
uri: new System.Uri("http://localhost:9200")
);
defaultSettings.SetJsonSerializerSettingsModifier(s => {
s.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
});
defaultSettings.SetConnectionStatusHandler(c => {
if(!c.Success) throw new Exception(c.ToString());
});
defaultSettings.SetDefaultIndex("projects");
执行代码
public ActionResult Search(String searchTerm) {
var result = this.searchClient.Search<ProjectIndexModel>(
descriptor: new SearchDescriptor<ProjectIndexModel>().Index("projects").AllTypes().Query(
query: q => q.QueryString(qs => qs.Query(searchTerm)
)
));
// or
/*
var results = this.searchClient.Search<ProjectIndexModel>(s =>
s.Index("projects").Type("project").Query(q =>
q.Term(f => f.ProblemDefinition, searchTerm) ||
q.Term(f => f.Name, searchTerm) ||
q.Term(f => f.SuggestedSolution, searchTerm) ||
q.Term(f => f.Initiator, searchTerm)
)
);
*/
return Json(result.Documents.ToList());
}
索引在应用程序启动时启动:
foreach(var project in this.dbContext.Projects) {
var indexModel = Mapper.Map<ProjectIndexModel>(project);
searchClient.Index(indexModel, "projects", "project", indexModel.Id.ToString());
}
数据库中存在Indexes(这与我现在的不完全相同,但架构保持不变)。
我尝试了什么:
控制器操作返回(默认)11个文档的 10次。它完全被忽略,没有明显的错误。
Fiddler
对{host:9200}/_search
和{host:9200}/projects/project/_search
POST 请求的查询给出了正面结果(1次点击):
{
"query": {
"query_string": {
"query": "original"
}
}
}
问题是什么?
答案 0 :(得分:1)
问题不在NEST
中。在探索results.ConnectionStatus.ToString()
之后,我发现问题出现在我的客户端代码中。我忽略了我发送Fiddler
而未指定POST
:
{searchTerm: $scope.searchTerm}