如何在Elasticsearch中为格式为JSON的文件创建一个带整数字段的索引



我正在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上的Discover标签是这样的:1

请告诉我哪里出了问题。

正如你提到的,我试过了,但没有帮助。经过多次尝试和错误之后,我意识到我的映射是不正确的。我终于写出了正确的映射,现在它工作正常了。Kibana将Jobid和TenantId识别为数字。我是JSON、kibana、Bulk、Elastic的新手,所以了解映射的工作原理需要一些时间。

相关内容

最新更新