2015-11-03 75 views
0

如何聚集在其上具有一格式11/03/2015即治療字符串作爲日期,而無需重新索引類型的字符串字段?例如,考慮的映射關係對一個Elasticsearch index:sporttype:athlete如何聚集在字符串類型的elasticsearch字段,其包括一斜槓(/)

curl -XPUT "http://localhost:9200/sports/" -d' 
{ 
    "mappings": { 
    "athlete": { 
     "properties": { 
      "birthdate": { 
      "type": "string"  
      }, 
      "name": { 
      "type": "string" 
      }, 
      "score": { 
      "type": "integer" 
      }, 
      "sport": { 
      "type": "string" 
      } 
     } 
    } 
    } 
} 

集結上birthdate出現使用/分離字段,因此聚集體上11/03/2015作爲11032015而不是採取作爲一個整體和聚集在它。如何解決這個問題? :

"buckets": [ 
     { 
      "key": "2015", 
      "doc_count": 24 
     }, 
     { 
      "key": "11", 
      "doc_count": 21 
     }, 
     { 
      "key": "03", 
      "doc_count": 3 
     } 
     ] 

回答

0

ES映射默認爲分析儀。將索引更改爲not_analyzed解決了問題:

curl -XPUT "http://localhost:9200/sports/" -d' 
{ 
"mappings": { 
    "athlete": { 
     "properties": { 
     "birthdate": { 
      "type": "string", "index" : "not_analyzed"  
      }, 
     "name": { 
     "type": "string" 
     }, 
     "score": { 
     "type": "integer" 
     }, 
     "sport": { 
     "type": "string" 
      } 
     } 
     } 
    } 
    }