2015-11-03 78 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" 
      } 
     } 
     } 
    } 
    }