NEST query for Elasticsearch not working -


we using nest api work elasticsearch using c#. while can insert data, queries reference specific fields in object not working.

for example, given following class:

internal class magazine {    public magazine(string id, string title, string author)    {       id = id;       title = title;       author = author;    }     public string id { get; set; }    public string title { get; set; }    public string author { get; set; } } 

objects of class created , inserted elasticsearch follows:

magazine mag1= new magazine("1", "soccer review", "john smith"); magazine mag2= new magazine("2", "cricket review", "john smith");  uri node = new uri("http://localhost:9200"); connectionsettings settings = new connectionsettings(node, defaultindex: "mag-application"); elasticclient client = new elasticclient(settings); client.index(mag1); client.index(mag2); 

the following query works, , returns 2 rows:

var searchresults = client.search<magazine>(s => s.from(0).size(20)); 

but 1 returns nothing:

var searchresults = client.search<magazine>(s => s.from(0).size(20).query(q => q.term(p => p.author, "john smith"))); 

what wrong?

since using standard analyzer (default option) "john smith" string broken 2 tokens "john" , "smith".

the term query :

matches documents have fields contain term (not analyzed).

that say, phrase searching not pass aforementioned analysis process.

try searching

client.search<magazine>(s => s.from(0).size(20).query(q => q.term(p => p.author, "john"))); 

or use match query 1 below:

client.search<magazine>(s => s.from(0).size(20)..query(q => q.match(m => m.onfield(p => p.author).query("john smith")) 

check in official documentation term query more information.


Comments

Popular posts from this blog

c# - SharpSsh Command Execution -

python - Specify path of savefig with pylab or matplotlib -

How to run C# code using mono without Xamarin in Android? -