asp.net mvc 3 - Why do I get 0 match from ElasticSearch query (C#)? -


i have code should return 5 matches search.

if try query in browser, 5 results:

http://localhost:9200/_search?q=testing 

if user sense editor shows 5 results:

server=localhost:9200 post _search {     "query": {         "query_string": {             "query": "testing"         }     } } 

but c# code in controller fails match. missing?

uri localhost = new uri("http://localhost:9200");             var setting = new connectionsettings(localhost);             setting.setdefaultindex("videos");             var client = new elasticclient(setting);              var result = client.search<searchhint>(                 body => body.query(                     query => query.querystring(                         qs => qs.query(keys))));              var results = new searchresults()             {                 results = result.documents.tolist() <-- has 0 items             }; 

edit 1:

public class searchhint     {         public string id { get; set; }         public string title { get; set; }         public int numitems { get; set; }         public bool islist { get; set; }          public searchhint(string id, string title, int numitems, bool islist)         {             id = id;             title = title;             numitems = numitems;             islist = islist;         }     } 

edit 2: there 4 types in index (videos\list, videos\video, videos\author, videos\category). search should search types not particular type.

i think issue related way nest defaulting types search. unless have specified , [elastictype] attribute on searchhint class query elasticsearch following url:

 /_all/searchhint/_search 

try adding typename corresponds type using in index, class definition, following (replacing mytype appropriate value index. also, if fields on indexed items not match default mapping conventions (camel cased) not data populated.

 [elastictype(name = "mytype"]  public class searchhint  {        // map field name title in index.        //use following property specify alternate name        //[elasticproperty(name="title")]        public string title { get; set;}  } 

please see nest documentation on inference overview of how works.

update: previous applies searching within single type. if want search across multiple types, need specify .alltypes() on search query , there not need specify [elastictype] attribute on class.

            var result = client.search<searchhint>(                 body => body                   .alltypes()                   .query(                     query => query.querystring(                         qs => qs.query(keys)))); 

Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -