c# - 如何在Elasticsearch中启用字段数据

标签 c# .net elasticsearch

我正在尝试在Elasticsearch中启用字段数据,但是我仍然遇到相同的错误。
谁能告诉我我所缺少的吗?

.NET代码

var resByApp = client.Search<ApiCall>(s => s.Aggregations(a => a
                    .Filter("my_filter", f => f
                          .Filter(fd => fd
                               .DateRange(r => r
                                   .GreaterThan(DateTime.UtcNow.ToBeginOfDay().AddDays(-DefaultDaysRange))
                                   .Field(p => p.CreatedDate)
                               )
                               &&
                               fd.Term(t => t.ServiceId, serviceId)
                           )
                    .Aggregations(ag => ag
                              .Terms("app_agg", st => st
                                  .Field(af => af.AppId))
                              )
                          )));

调试信息:
Invalid NEST response built from a unsuccessful low level call on POST: /abc_apicalls/apicall/_search
# Audit trail of this API call:
 - [1] BadResponse: Node: http://localhost:9200/ Took: 00:00:00.0459990
# ServerError: ServerError: 400Type: search_phase_execution_exception Reason: "all shards failed" CausedBy: "Type: illegal_argument_exception Reason: "Fielddata is disabled on text fields by default. Set fielddata=true on [appId] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory.""
# OriginalException: System.Net.WebException: The remote server returned an error: (400) Bad Request.
   at System.Net.HttpWebRequest.GetResponse()
   at Elasticsearch.Net.HttpConnection.Request[TReturn](RequestData requestData) in C:\Users\russc\source\git\elasticsearch-net-5.x\src\Elasticsearch.Net\Connection\HttpConnection.cs:line 164
# Request:
{"aggs":{"my_filter":{"filter":{"bool":{"must":[{"range":{"createdDate":{"gt":"2017-03-26T00:00:00"}}},{"term":{"serviceId":{"value":2}}}]}},"aggs":{"app_agg":{"terms":{"field":"appId"}}}}}}
# Response:
{"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"Fielddata is disabled on text fields by default. Set fielddata=true on [appId] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory."}],"type":"search_phase_execution_exception","reason":"all shards failed","phase":"query","grouped":true,"failed_shards":[{"shard":0,"index":"abc_apicalls","node":"oYXnz0dhTZ6Bs5ZpspH1hg","reason":{"type":"illegal_argument_exception","reason":"Fielddata is disabled on text fields by default. Set fielddata=true on [appId] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory."}}],"caused_by":{"type":"illegal_argument_exception","reason":"Fielddata is disabled on text fields by default. Set fielddata=true on [appId] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory."}},"status":400}

我尝试了什么:
PUT abc_apicalls/apicall/text
{
  "properties": {
    "appId": { 
      "type":     "text",
      "fielddata": true
    }
  }
}

这是GET abc_apicalls的结果
{
  "abc_apicalls": {
    "aliases": {},
    "mappings": {
      "apicall": {
        "properties": {
          "appId": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "properties": {
            "properties": {
              "appId": {
                "properties": {
                  "fielddata": {
                    "type": "boolean"
                  },
                  "type": {
                    "type": "text",
                    "fields": {
                      "keyword": {
                        "type": "keyword",
                        "ignore_above": 256
                      }
                    }
                  }
                }
              }
            }
          },
    ...
  }
}

资源:https://www.elastic.co/guide/en/elasticsearch/reference/current/fielddata.html

最佳答案

类型错误,这是启用字段数据的正确方法

PUT abc_apicalls/_mapping/apicall
{
   "apicall": {
      "properties": {
        "appId": {
          "type": "text",
          "fielddata": true
        }
      }
   }
}

关于c# - 如何在Elasticsearch中启用字段数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43229616/

相关文章:

c# - 如何从 C# 调用 Java 代码?

c# - 同一实体的多个 Dto

c# - 隐式与显式接口(interface)实现

elasticsearch - 将线程 View 存储在ElasticSearch中

c# - 为什么 `switch` 代码的圈复杂度比 'if-else' 高

c# - Entity Framework 6-使用我的getHashCode()

c# - 分割字符串并将索引之一转换为int

c# - 如何使用 HTML 输入文件类型限制文件类型?

elasticsearch - 是否可以存储带有换行符和注释的ElasticSearch脚本化指标?

elasticsearch - Elasticsearch ActiveMQ River配置