Elasticsearch Kibana中的映射数组(文本、数据)



我正试图发布这些标签:

POST dicom1/_doc/1
{
"(0008,0005)": ["SpecificCharacterSet", "ISO_IR 100"], 
"(0008,0008)": ["ImageType", "ORIGINAL"], 
"(0008,0020)": ["StudyDate", "2002-04-01"],
"(0008,0023)": ["ContentDate", "2002-04-01"],
... 
}

但我得到了一个例外:

"type": "illegal_argument_exception",
"reason": "mapper [(0008,0020)] of different type, current_type [date], merged_type [text]"

所以我尝试了:

PUT dicom1
{
"mappings": {
"_doc":{
"properties": {
"(0008,0020)": {
"type": ["text","date"],
},
"(0008,0023)": {
"type": ["text" ,"date"],
},
...

但上面写着"坏字符串"如何在不更改结构的情况下发布json?

DICOM有一套关于图像命名约定的标准。

数组本身就是一个键值。基本上,对于特定的图像,有一个叫做tagtag namevalue的东西。

简而言之,你可以说你有元组。例如

tag - "(0008,0020)"
tag_name - "StudyDate"
tag_value - 2004-01-01

我为DICOM图像提出了以下设计,我认为它适用于大多数用例。请参阅下面的映射、示例文档、查询和响应:

映射:

PUT dicom
{
"mappings": {
"properties": {
"dicom_tags_text":{
"type": "nested",
"properties": {
"tag": {
"type": "keyword"
},
"tag_name": {
"type": "keyword"
},
"tag_value":{
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
}
}
}
}
},
"dicom_tags_date":{
"type": "nested",
"properties": {
"tag": {
"type": "keyword"
},
"tag_name": {
"type": "keyword"
},
"tag_value":{
"type": "date",
"format": "yyyy-MM-dd"
}
}
}
}  
}
}

以下是我使用的一些概念

  • 嵌套数据类型
  • 文本数据类型----->用于部分匹配
  • 关键字数据类型----->用于精确匹配
  • 日期数据类型

每个图像都有两类数据,一类是具有text字段的数据,另一类是带有date字段的数据。根据是否要存储任何其他格式的数据,可以添加更多字段。

请注意,为了简单起见,我对字符串数据使用了关键字。这是因为它们用于精确匹配。您也可以使用text数据,但请花点时间了解两者之间的区别。

示例文件:

POST dicom/_doc/1
{
"dicom_tags_text": [
{
"tag": "(0008,0005)",
"tag_name": "SpecificCharacterSet",
"tag_value": "ISO_IR 100"
},
{
"tag": "(0004,1511)",
"tag_name": "SOPInstanceId",
"tag_value": "1001"
}
],
"dicom_tags_date": [
{
"tag": "(0008,0020)",
"tag_name": "StudyDate",
"tag_value": "2002-04-01"
},
{
"tag": "(0008,0023)",
"tag_name": "ContentDate",
"tag_value": "2002-04-01"
}  
]
}
POST dicom/_doc/2
{
"dicom_tags_text": [
{
"tag": "(0008,0005)",
"tag_name": "SpecificCharacterSet",
"tag_value": "ISO_IR 100"
},
{
"tag": "(0004,1511)",
"tag_name": "SOPInstanceId",
"tag_value": "1004"
}
],
"dicom_tags_date": [
{
"tag": "(0008,0020)",
"tag_name": "StudyDate",
"tag_value": "2020-01-01"
}  
]
}

请注意,我在上面创建了两个文档,并仔细注意我是如何构建这些文档的。您可以将其与映射进行交叉检查,以便首先了解映射。

请求查询:

现在假设您的用例是检索所有具有ISO_IR 100字符集的文档,其中StudyDate2019-01-01之后完成。

以下是查询方式:

POST dicom/_search
{
"query": {
"bool": {
"must": [
{
"nested": {
"path": "dicom_tags_text",
"query": {
"bool": {
"must": [
{
"term": {
"dicom_tags_text.tag_name": "SpecificCharacterSet"
}
},
{
"match": {
"dicom_tags_text.tag_value": "iso ir 100"
}
}
]
}
}
}
},
{
"nested": {
"path": "dicom_tags_date",
"query": {
"bool": {
"must": [
{
"term": {
"dicom_tags_date.tag_name": "StudyDate"
}
},
{
"range": {
"dicom_tags_date.tag_value": {
"gte": "2019-01-01"
}
}
}
]
}
}
}
}
]
}
}
}

注意,对于nested数据类型,我们需要使用nested queries。我对关键字类型使用了术语查询,对文本字段使用了简单的匹配查询。请阅读上述链接以了解更多信息。

以下是响应的显示方式:

{
"took" : 1,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 1,
"relation" : "eq"
},
"max_score" : 2.4854383,
"hits" : [
{
"_index" : "dicom",
"_type" : "_doc",
"_id" : "2",
"_score" : 2.4854383,
"_source" : {
"dicom_tags_text" : [
{
"tag" : "(0008,0005)",
"tag_name" : "SpecificCharacterSet",
"tag_value" : "ISO_IR 100"
},
{
"tag" : "(0004,1511)",
"tag_name" : "SOPInstanceId",
"tag_value" : "1004"
}
],
"dicom_tags_date" : [
{
"tag" : "(0008,0020)",
"tag_name" : "StudyDate",
"tag_value" : "2020-01-01"
}
]
}
}
]
}
}

如果这对你有帮助,请告诉我!!

最新更新