elasticsearch - 将Elasticsearch查询转换为.net NEST

标签 elasticsearch nest

如何将这个Elasticsearch匹配查询写入C#.net NEST。

 GET /disney2/character/_search
     {
     "query": {
     "match": {
     "name.phonetic": {
     "query": "Jahnnie Smeeth",
    "operator": "and"
     }
     }
     }
     } 

最佳答案

使用对象初始化器的语法:

        ConnectionSettings _clientSettings = new ConnectionSettings(new Uri("http://localhost:9200/disney2"));
        var client = new ElasticClient(_clientSettings);
        var query = new SearchRequest<disney>(); // You're going to want to replace <object> with a model corresponding to your type, or specify the type via string
        var matcher = new MatchQuery();
        matcher.Field = "name.phonetic";
        matcher.Query = "Jahnnie Smith";
        matcher.Operator = Operator.And;
        query.Query = matcher;

        //var res = elasticClient.Search<disney>(query);
        var res = client.Search<disney>(query);

关于elasticsearch - 将Elasticsearch查询转换为.net NEST,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46958983/

相关文章:

c# - 如何将 MSSQL 同步到 Elasticsearch?

elasticsearch - 应该保留ElasticSearch.NET客户端的哪些部分以使SniffingConnectionPool正常工作?

elasticsearch - 使用应用搜索来搜索诸如 “c#”之类的单词

php - PHP Elasticsearch集群

elasticsearch - 如何获取我的metricbeat文件的系统参数值?

c# - 线程锁内的多线程

php - 合并键存储桶中的doc_count结果

elasticsearch - 在多个条件下查询 Elasticsearch

java - 如何通过 bulkrequest 更新嵌套的 elasticsearch 值?

c# - 使用 NEST C# 的 ElasticSearch 2.x GeoPoint 映射