如何在包含斜杠的类型字符串的elasticsearch字段上聚合(/)

时间:2015-11-03 14:40:45

标签: elasticsearch

如何聚合格式为index:sport的字符串类型的字段,即将字符串视为日期而不重新编制索引?例如,考虑Elasticsearch type:athletecurl -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分隔字段,因此在11上汇总为032015"buckets": [ { "key": "2015", "doc_count": 24 }, { "key": "11", "doc_count": 21 }, { "key": "03", "doc_count": 3 } ] 而非作为一个整体并聚合在上面。如何解决这个问题? :

class="datamaps-subunit JPN"

2 个答案:

答案 0 :(得分:0)

您的生日映射不应为字符串类型。相反它应该是" date"。如果需要,您还可以使用映射指定格式。这个链接可以帮到你。

https://www.elastic.co/guide/en/elasticsearch/reference/1.4/mapping-core-types.html#date

答案 1 :(得分: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"
          }
        }
      }
    }
  }