Searching ElasticSearch using NEST C# Client

前端 未结 4 1191
-上瘾入骨i
-上瘾入骨i 2021-02-06 10:37

I started looking around for a search engine and after some reading I decided going with ElasticSearch (which is quite amazing :)), my project is in C# so I looked around for a

4条回答
  •  春和景丽
    2021-02-06 11:23

    If the anonymous types above aren't your thing, you can just use JObjects from json.net and build your query that way. Then you can run it the same way above.

    JObject query = new JObject();
    query["query"] = new JObject();
    query["query"]["text"] = new JObject();
    query["query"]["text"]["_all"] = searchTerm;
    query["from"] = start;
    query["size"] = maxResults;
    string stringQuery = JsonConvert.SerializeObject(query);
    var results = connectedClient.SearchRaw(stringQuery);
    

    I like this way better because the DSL in ES uses reserved keywords in C#, like bool, so I don't have to do any escaping.

提交回复
热议问题