c# - nest query returns weird results. elasticsearch -
this client code:
settings
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");
executing code
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) ) ); */ homecoming json(result.documents.tolist()); }
indexing launched @ application start:
foreach(var project in this.dbcontext.projects) { var indexmodel = mapper.map<projectindexmodel>(project); searchclient.index(indexmodel, "projects", "project", indexmodel.id.tostring()); }
indexes nowadays in database (that's not quite same have now, schema stayed same).
what have tried:
controller action returns (default) 10 hits of 11 documents. it's searching ignored entirely, without visible errors.
fiddler
gave positive result (1 hit) both {host:9200}/_search
, {host:9200}/projects/project/_search
post requests query:
{ "query": { "query_string": { "query": "original" } } }
what's problem?
problem not in nest
. after exploring results.connectionstatus.tostring()
, showed nail fiddler
did, found problem in client code. overlooked sending post
without {searchterm: $scope.searchterm}
specified:
$http({ url: '/projects/search', method: "post", data: { searchterm: $scope.searchterm } }) .success(function(data, status, headers, config) { $scope.projects = data.documents; }).error(function(data, status, headers, config) { console.log('error: ' + data); });
c# .net json elasticsearch nest
No comments:
Post a Comment