arrays - Elasticsearch Kibana中的映射数组(文本,数据)

标签 arrays json elasticsearch tags 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"
          }
        }
      }
    }  
  }
}

以下是我使用过的一些概念
  • Nested Datatype
  • Text Datatype ----->用于部分匹配
  • Keyword Datatype ----->用于精确匹配
  • Date Datatype

  • 每个图像将具有两类数据,一类为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/

    相关文章:

    c++ - SDL 2.0/C++ - 如何创建 "SDL_Texture"数组?

    php - 在 elasticaserch 中应用游标分页

    java - 静态数组长度,替换值

    javascript - MVC 如何接收来自 JSON 的对象数组?

    json - 如何避免解析 ISuperObject 类型字段中的 json 对象

    json - 可以在 SQL JSON 中混合字符串和对象输出吗?

    java - 创建嵌入式节点时出现 ElasticSearch 异常

    elasticsearch copy_to 字段与聚合的行为不符合预期

    ruby - 检查数组元素data[i][j][k]是否存在

    c - 为什么结构分配适用于结构中的数组