我正在尝试发布以下标签:
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有一套有关图像命名约定如何执行的标准。
数组本身就是键值。基本上,对于该特定图像,您具有称为tag
,tag name
和value
的名称。
简而言之,您可以说您有元组。例如
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
字符集且在StudyDate
之后完成2019-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
。我已经将Term Query用于keyword类型,并将简单的Match Query用于text字段。请阅读上述链接以了解更多信息。以下是响应的显示方式:
{
"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"
}
]
}
}
]
}
}
让我知道这是否会对您有所帮助!!
关于arrays - Elasticsearch Kibana中的映射数组(文本,数据),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60815612/