映射中的not_analyzed被忽略

时间:2016-08-09 08:54:22

标签: perl elasticsearch kibana

TLDR:即使映射显示not_analyzed,也会对某些字段进行分析。

我有几组数据,每个数据都根据集合中包含的日期发送到Elasticsearch索引(它提供索引名称,如index-25012016)。有些集合具有相同的日期,因此具有相同的索引。

我使用以下perl命令将映射发送到ES

print `curl -s -XPUT "http://$ELASTIC_SEARCH_URL/$currentIndexName?pretty" -d ' $mapping'`

其中$ currentIndexName和$ mapping是分别看起来像index-25012016

的字符串
{
    "mappings": {
        "myMappingType": {
            "properties": {
                "present": {
                    "type":"boolean"
                },
                "records": {
                    "type":"integer"
                },
                "batchID": {
                    "type":"string",
                    "index":"not_analyzed"
                },
                "version": {
                    "type":"string",
                    "index":"not_analyzed"
                },
                "date": {
                    "type":"date",
                    "format":"yyyy-MM-dd"
                },
                "packageCreationDate": {
                    "type":"date",
                    "format":"MM/dd/yyyy-HH:mm"
                }
            }
        }
    }
}

还有一些字段。 除了我先前已经完成的任何$ currentIndexName之外,对所有集重复此命令。 运行命令时,ES的答案是

{
  "acknowledged" : true
}

是否跳过或实现了此映射步骤,然后我使用`curl -s -XPOST "$ELASTIC_SEARCH_URL/$currentIndexName/_bulk?pretty" --data-binary \@$outputFileName`;将数据发送到ES 其中$ outputFileName是json文件的名称。

问题在于即使我指定not_analyzed,在Kibana / Settings / Indices中,字符串字段也被标记为已分析和索引,我只想索引。因此,例如,由于版本字段对于所有人都是相同的(" 3.2.506 64位"),饼图将显示三个相等的片段" 3.2.506", " 64"和" bit"而不是整个未切割的" 3.2.506 64位"馅饼。但是,不会分析布尔值,数字,日期字段和元字段。

Kibana中的索引模式匹配所有这些索引(index- *)并使用date作为基于时间的事件字段。 我试图在数据发送后重新创建索引模式,它不会改变任何东西。 我在Windows 7上并且没有使用logstash。

编辑:由于我现在做了很多测试,每次脚本启动时,我都会删除数据,然后再迭代这些数据集     print `curl -s -XDELETE "http://localhost:9200/index-*?pretty`; 因此脚本看起来像:

Remove data  
for each set in allSets 
    mapping (if not already mapped in a previous iteration)  
    send data to ES 

1 个答案:

答案 0 :(得分:1)

无法更新现有数据的映射。您需要使用正确的映射创建新索引,并将文档重新索引到该索引中。以下是ES文档的链接:https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping.html#_updating_existing_mappings

您还可以使用索引模板自动将映射应用于新创建的索引:https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html