2017-08-03 25 views
0

以下映射中字段版本的類型是日期。但是在groups/_mapping中列出的版本類型是文本。映射或設置有什麼問題嗎?謝謝。類型日期已被隱藏到elasticsearch中的文本(v5.4.0)

映射:

PUT groups 

{ 
    "settings": { 
    "index.mapping.ignore_malformed": true 
    }, 
    "mappings": { 
    "shop": { 
     "_all": { "enabled": false }, 
     "dynamic": "false", 
     "date_detection" : false, 
     "properties": { 
      "sid":  { "type": "keyword"}, 
      "version": { 
       "type": "date", 
       "format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis" 
      } 
     } 
    } 
    } 
} 

此結果是。

{ 
    "acknowledged": true, 
    "shards_acknowledged": true 
} 

結果從http://host:9200/groups/_mapping

{ 
    "groups": { 
    "mappings": { 
     "shop": { 
     "properties": { 
      "sid": { 
      "type": "text", 
      "fields": { 
       "keyword": { 
       "type": "keyword", 
       "ignore_above": 256 
       } 
      } 
      }, 
      "version": { 
      "type": "text", 
      "fields": { 
       "keyword": { 
       "type": "keyword", 
       "ignore_above": 256 
       } 
      } 
      } 
     } 
     } 
    } 
    } 
} 

插入數據如下:

{'sid': '772634b9b9a8437f9cbfaec2b546f8af', 'version': '20131209 15:19:04'} 

響應:

{ 
    '_id': '772634b9b9a8437f9cbfaec2b546f8af', 
    '_index': 'groups_version', 
    '_shards': {'failed': 0, 'successful': 2, 'total': 2}, 
    '_type': 'shop', 
    '_version': 1, 
    'result': 'created', 
} 

的asdas

+0

我看起來像你的'PUT groups'請求的整個身體被忽略。 '_mapping'不會只顯示日期字段的錯誤類型 - 如果索引是用你的PUT的整個體創建的,它還應該顯示'「sid」:{「type」:「keyword」}','「date_detection」: false'和'「_all」:{「enabled」:false}'。我重新創建了這個問題,對我來說這一切都很好(v 5.4)。你確定在創建索引時,你會得到200 OK嗎?「確認」:true'作爲響應? – Joanna

+0

我使用kibana來創建索引並通過python腳本插入數據。是的,「已確認」:返回true。我也在使用v5.4.0。 –

回答

1

我想我可能知道什麼是要去 - 在Kibana當你把PUT group和身體{}之間的空行並不身體追加到reguest和發送的唯一要求是:

curl -XPUT "http://localhost:9200/groups" 

這就是爲什麼你用text得到標準映射。但是,如果你刪除空行everythnig是正常的並且該請求被髮送:

curl -XPUT "http://localhost:9200/groups" -H 'Content-Type: application/json' -d' 
{ "body": { 
    "settings": { 
    "index.mapping.ignore_malformed": true 
    }, 
    "mappings": { 
    "shop": { 
     "_all": { "enabled": false }, 
     "dynamic": "false", 
     "date_detection" : false, 
     "properties": { 
      "sid":  { "type": "keyword"}, 
      "version": { 
       "type": "date", 
       "format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis" 
      } 
     } 
    } 
    } 
} 
}' 

這是很容易檢查,當你點擊「扳手」按鈕,然後在「複製爲捲曲什麼是真正發送「在某處貼吧:

enter image description here

+0

哇,你只是保存我的一天。非常感謝。 –