【问题标题】:How to create an index with integer fields in Elasticsearch for the JSON file of format?如何在 Elasticsearch 中为 JSON 格式的文件创建带有整数字段的索引?
【发布时间】:2016-08-07 06:59:33
【问题描述】:

我正在尝试在 Elasticsearch 中为 JSON 格式的文件创建索引:

{ "index" : { "_index" : "entity", "_type" : "type1", "_id" : "0" } }
{     "eid":"guid of Event autogenerated",     "entityInfo": {         "entityType":"qualityevent",         "defaultLocale":"en-US"     },     "systemInfo":     {         "tenantId":"67"     },     "attributesInfo" : {         "jobId":"21",         "matchStatus": "new"     }      }
{ "index" : { "_index" : "entity", "_type" : "type1", "_id" : "1" } }
{     "eid":"guid of Event autogenerated",     "entityInfo":     {         "entityType":"qualityevent",         "defaultLocale":"en-US"     },     "systemInfo":     {         "tenantId":"67"     },     "attributesInfo" : {         "jobId":"20",         "matchStatus": "existing"     }     }

我希望字段 jobId 和tenantId 是整数。

我在 curl 命令中给出以下映射:

curl -XPUT http://localhost:9200/entity -d '
{
    "mappings": {
        "entityInfo":
        {
            "properties" : {
            "entityType" : { "type":"string","index" : "not_analyzed"},
            "defaultLocale":{ "type":"string","index" : "not_analyzed"}
            }
        },
        "systemInfo":
        {
            "properties" : {
            "tenantId": { "type" : "integer" }
            }
        },
        "attributesInfo" : 
        {
            "properties" : {
            "jobId": { "type" : "integer" },
            "matchStatus": { "type":"string","index" : "not_analyzed"}
            }
        }
    }
}
'; 

这不会给我一个错误。但是,它会创建新的空字段 jobId 和 tenantId 作为整数,并将现有数据作为字符串保存到 attributesInfo.jobId。 systemInfo.tenantId 也是如此。我想在 Kibana 中使用这两个字段进行可视化。我目前无法使用它们,因为它们是空的。

我是 Kibana 和 Elasticsearch 的新手,所以我不确定映射是否正确。

我也尝试了其他几个映射,但它们给出了错误。上面的映射没有报错。

这是 Kibana 上的“发现”选项卡的外观:1

请告诉我哪里出错了。

【问题讨论】:

  • 我可以看到 jobId 和tenantId 有字符串值(“40”和“67”)。尝试插入 "jobId"=40 & "tenantId": 67 看看它是否有效。

标签: json elasticsearch mapping kibana-4 elasticsearch-bulk-api


【解决方案1】:

我按照你的说法试过了,但没有帮助。经过大量试验和错误后,我意识到我的映射不正确。我终于写了正确的映射,现在它可以正常工作了。 Jobid 和 TenantId 被 Kibana 识别为数字。我是 JSON、kibana、Bulk、Elastic 的新手,所以需要时间来了解映射的工作原理。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-08-31
    • 1970-01-01
    • 2013-07-22
    • 1970-01-01
    • 2021-09-02
    • 1970-01-01
    • 1970-01-01
    • 2022-01-21
    相关资源
    最近更新 更多