Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/274.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何添加未分析的文本关键字,以便在使用NEST的elasticsearch中进行排序?_C#_.net_<img Src="//i.stack.imgur.com/RUiNP.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">elasticsearch_Nest - Fatal编程技术网 elasticsearch,nest,C#,.net,elasticsearch,Nest" /> elasticsearch,nest,C#,.net,elasticsearch,Nest" />

C# 如何添加未分析的文本关键字,以便在使用NEST的elasticsearch中进行排序?

C# 如何添加未分析的文本关键字,以便在使用NEST的elasticsearch中进行排序?,c#,.net,elasticsearch,nest,C#,.net,elasticsearch,Nest,我正在使用C#中的NEST客户端与我的elasticsearch集群进行交互 我正在尝试根据字符串值进行排序。但是,我不能这样做,因为这个字段是文本字段 因此,我想添加一个关键字字段,并基于该字段进行排序,以获得更好的性能。大概是这样的: { "mappings": { "my_type": { "properties": { "my_field": { "type": "text", "fields": {

我正在使用C#中的NEST客户端与我的elasticsearch集群进行交互

我正在尝试根据字符串值进行排序。但是,我不能这样做,因为这个字段是文本字段

因此,我想添加一个关键字字段,并基于该字段进行排序,以获得更好的性能。大概是这样的:

{
  "mappings": {
    "my_type": {
      "properties": {
        "my_field": { 
          "type": "text",
          "fields": {
            "keyword": { 
              "type": "keyword"
            }
          }
        }
      }
    }
  }
}
但我不确定如何最好地将其转换到NEST客户端,然后如何根据
my_field.keyword
进行排序

我把它作为映射,但因为我不确定sort子句是什么样子,所以我不确定如何测试它

.Mappings(m => m
    .Map<Product>(mm => mm
        .Properties(p => p
            .Text(t => t
                .Name(n => n.ProductName)
                .Analyzer("custom")
                .Fields(f => f
                    .Keyword(k => k)
                )
            )
        )
    )
)
.Mappings(m=>m
.Map(mm=>mm
.Properties(p=>p
.Text(t=>t
.Name(n=>n.ProductName)
.Analyzer(“自定义”)
.Fields(f=>f
.Keyword(k=>k)
)
)
)
)
)
我一直在努力翻阅NEST文档,但这种边缘功能更难找到。

要引用多字段的子字段,可以在成员访问lambda表达式中使用
.Suffix(“suffixname”)
扩展方法

client.Search(s=>s
.Query(q=>q
.Match(m=>m
.Field(f=>f.Description.Suffix(“关键字”))
.Query(“狼獾”)
)
)
);
这将导致查询

{
  "query": {
    "match": {
      "description.keyword": {
        "query": "Wolverine"
      }
    }
  }
}
如果愿意,也可以指定字符串

client.Search(s=>s
.Query(q=>q
.Match(m=>m
.Field(“description.keyword”))
.Query(“狼獾”)
)
)
);

使用多个字段和分析器映射
字符串
属性:。使用
.Suffix(“”
参考进行排序谢谢!这最终奏效了。如果你把这个作为答案贴出来,我会把它标记为正确的,罗斯。