2016-12-09 76 views
1

我知道這是一個新的更改,但是我看不到這個映射有什麼問題。這是從通過_mapping呼叫ElasticSearch註冊領域的映射採取:ElasticSearch 5.x在文本字段上排序問題

"key": { 
    "type": "text", 
    "fields": { 
     "keyword": { 
      "type": "keyword", 
      "ignore_above": 256 
     } 
    } 
} 

當我有點用「鑰匙」領域,我得到這個例外。我也嘗試添加fieldData = true,但這也沒有奏效。

Caused by: RemoteTransportException[[_6qwpaI][127.0.0.1:9300][indices:data/read/search[phase/query]]]; nested: IllegalArgumentException[Fielddata is disabled on text fields by default. Set fielddata=true on [key] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory.]; 
Caused by: java.lang.IllegalArgumentException: Fielddata is disabled on text fields by default. Set fielddata=true on [key] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory. 
    at org.elasticsearch.index.mapper.TextFieldMapper$TextFieldType.fielddataBuilder(TextFieldMapper.java:335) 
    at org.elasticsearch.index.fielddata.IndexFieldDataService.getForField(IndexFieldDataService.java:111) 
    at org.elasticsearch.index.query.QueryShardContext.getForField(QueryShardContext.java:167) 
    at org.elasticsearch.search.sort.FieldSortBuilder.build(FieldSortBuilder.java:281) 
    at org.elasticsearch.search.sort.SortBuilder.buildSort(SortBuilder.java:151) 
    at org.elasticsearch.search.SearchService.parseSource(SearchService.java:678) 
    at org.elasticsearch.search.SearchService.createContext(SearchService.java:536) 
    at org.elasticsearch.search.SearchService.createAndPutContext(SearchService.java:502) 
    at org.elasticsearch.search.SearchService.executeQueryPhase(SearchService.java:243) 
    at org.elasticsearch.action.search.SearchTransportService.lambda$registerRequestHandler$6(SearchTransportService.java:276) 
    at org.elasticsearch.transport.TransportRequestHandler.messageReceived(TransportRequestHandler.java:33) 
    at org.elasticsearch.transport.RequestHandlerRegistry.processMessageReceived(RequestHandlerRegistry.java:69) 
    at org.elasticsearch.transport.TransportService$6.doRun(TransportService.java:550) 
    at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:527) 
    at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) 
    at java.lang.Thread.run(Thread.java:745) 

起初我以爲這可能與使用的字段(如key.keyword)的,但因爲我不這樣做,那麼我看不出有任何理由,爲什麼這是不工作。

我對ElasticSearch 5.x相當陌生,文檔自相矛盾,所以我希望有人能指出我正確的方向。這就是我指的是:

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

我基本上是試圖實現相同一直幹到5.x的這種原始的映射:

"mapping": { 
    "type": "string", 
    "fields": { 
     "raw": { 
      "type": "string", 
      "ignore_above": 256 
     }, 
     "english": { 
      "type": "string", 
      "analyzer": "english" 
     } 
    } 
} 

BTW,我覺得關鍵詞字段是自動生成的,因爲我甚至沒有在我的映射中定義它。

+0

你能解決這個問題嗎?我面臨着類似的問題:( – askids

+0

請看下面的答案,看看它是否有助於你的情況。 – juminoz

回答

1

使用此設置代替5.x. 「關鍵字」是未分析字符串的新類型。

{ 
    "mappings": { 
    "doc": { 
     "dynamic_templates": [ 
     { 
      "strings": { 
      "match_mapping_type": "string", 
      "mapping": { 
       "type": "text", 
       "fields": { 
       "raw": { 
        "type": "keyword", 
        "ignore_above": 256 
       }, 
       "english": { 
        "type": "text", 
        "analyzer": "english" 
       } 
       } 
      } 
      } 
     } 
     ] 
    } 
    } 
} 

下面是我在ElasticSearch論壇中從Lee Hinman那裏得到的解釋。

如果指數沒有映射一個字符串,ES在5.0以上,現在自動 創建 場的文本版本和關鍵字版本(下.keyword)。

這實際上相當混亂一些match_mapping_type不理解值「text」。

有此斷開,用於 match_mapping_type「動態」類型是場類型,不一定是ES 類型。例如,match_mapping_type只支持「long」,而不是 「integer」,因爲它映射到數據類型而不是ES類型。因此,即使ES本身使用「文本」和「關鍵字」, 的數據類型仍然是「字符串」,即 。

我同意這是混亂的,這兒有個PR: https://github.com/elastic/elasticsearch/pull/17285爲5.0以上,增加了這個 棄用記錄,我點開 https://github.com/elastic/elasticsearch/pull/22090所以6.0將拋出 異常時使用了無法識別的類型。