弹性搜索:将 CSV 转换为索引数组

Elastic Search: Transform CSV to array on index

我有一个包含来自 JDBC river 插件的 csv 字符串的字段,我希望它是一个整数数组。

我指定了以下包含转换的映射:

{
    "mytype" : {
        "transform": {
            "script":"ctx._source['AllowedAccountIds'] = ctx._source['AllowedAccountIds']?.tokenize(',')",
            "lang":"groovy"
        },
         "properties": {
           "AllowedAccountIds": { "type": "integer"},          
           "Name": { "type": "string" },
           "Description":{"type":"string"}
        }
    }
}

如果我使用 ?_source_transform 参数请求文档,我可以看到这种工作方式:

{
    "_index": "myindex",
    "_type": "mytype",
    "_id": "1",
    "_version": 1,
    "found": true,
    "_source": {
        "Name": "Lorem Ipsum",
        "AllowedAccountIds": [
            "1",
            "3",
            "19",
            "14",
            "26"
        ],
        "Description": "Vivamus ex libero, pellentesque ultricies sodales vitae, mollis a magna. Vestibulum est purus, placerat eu enim a, ullamcorper lacinia ligula. Nullam pellentesque tristique mollis. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; In feugiat augue sem, eu scelerisque augue gravida nec. Vivamus fermentum finibus arcu, at commodo sapien imperdiet ac. Ut posuere cursus neque, eu ornare lorem ornare sit amet. Vivamus pulvinar ultricies eros. Aliquam euismod ex non dapibus consequat. Donec tristique tortor id feugiat porttitor. Morbi turpis purus, vestibulum sit amet accumsan sed, ultricies quis justo."
    }
}

但如果我不指定参数,我会看到以下内容:

{
    "_index": "myindex",
    "_type": "mytype",
    "_id": "1",
    "_version": 1,
    "found": true,
    "_source": {
        "Name": "Lorem Ipsum",
        "AllowedAccountIds": "1,3,19,14,26",
        "Description": "Vivamus ex libero, pellentesque ultricies sodales vitae, mollis a magna. Vestibulum est purus, placerat eu enim a, ullamcorper lacinia ligula. Nullam pellentesque tristique mollis. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; In feugiat augue sem, eu scelerisque augue gravida nec. Vivamus fermentum finibus arcu, at commodo sapien imperdiet ac. Ut posuere cursus neque, eu ornare lorem ornare sit amet. Vivamus pulvinar ultricies eros. Aliquam euismod ex non dapibus consequat. Donec tristique tortor id feugiat porttitor. Morbi turpis purus, vestibulum sit amet accumsan sed, ultricies quis justo."
    }
}

我一直期待看到第一个结果。我是否误解了转换的用途?

任何人都可以阐明这一点吗?文档帮助不大。

编辑:虽然从 ElasticSearch.NET 查询时这似乎确实解决了我的问题 - 但我仍然想了解发生了什么。

根据文档 - http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-transform.html#mapping-transform

but the original source is stored in the _source

这意味着实际的 JSON 不会被转换,但是进入存储的数据(如果启用)和反向索引会被转换。

因此,您的搜索仅基于您转换后的内容,但您将检索的数据默认情况下不会转换。