【问题标题】:Elasticsearch Mapping for array数组的 Elasticsearch 映射
【发布时间】:2021-08-07 10:02:17
【问题描述】:

我有以下文档需要为 elasticsearch 进行映射

"table_1": {
        "title": "Spine Imaging Guidelines",
        "rows": [
            "Procedure Codes Associated with Spine Imaging \n3",
            "SP-1: General Guidelines \n5",
            "SP-2: Imaging Techniques \n15",
            "SP-3: Neck (Cervical Spine) Pain Without/With Neurological \nFeatures (Including Stenosis) and Trauma \n24",
            "SP-4: Upper Back (Thoracic Spine) Pain Without/With Neurological \nFeatures (Including Stenosis) and Trauma \n28",
            "SP-5: Low Back (Lumbar Spine) Pain/Coccydynia without \nNeurological Features \n31",
            "SP-6: Lower Extremity Pain with Neurological Features \n(Radiculopathy, Radiculitis, or Plexopathy and Neuropathy) With or \nWithout Low Back (Lumbar Spine) Pain \n35",
            "SP-7: Myelopathy \n39",
            "SP-8: Lumbar Spine Spondylolysis/Spondylolisthesis \n42",
            "SP-9: Lumbar Spinal Stenosis \n45",
            "SP-10: Sacro-Iliac (SI) Joint Pain, Inflammatory \nSpondylitis/Sacroiliitis and Fibromyalgia \n47",
            "SP-11: Pathological Spinal Compression Fractures \n50",
            "SP-12: Spinal Pain in Cancer Patients \n52",
            "SP-13: Spinal Canal/Cord Disorders (e.g. Syringomyelia) \n53",
            "SP-14: Spinal Deformities (e.g. Scoliosis/Kyphosis) \n55",
            "SP-15: Post-Operative Spinal Disorders \n58",
            "SP-16: Other Imaging Studies and Procedures Related to the Spine \nImaging Guidelines \n61",
            "SP-17: Nuclear Medicine \n65"
        ],
        "meta": {
            "page_no": 2,
            "page_text": "Spine Imaging \nGuidelines\n Procedure Codes Associated with Spine Imaging\n 3 SP-1: General Guidelines\n 5 SP-2: Imaging Techniques\n 15 SP-3: Neck (Cervical Spine) Pain Without/With Neurological \nFeatures (Including Stenosis) and Trauma\n 24 SP-4: Upper Back (Thoracic Spine) Pain Without/With Neurological \nFeatures (Including Stenosis) and Trauma\n 28 SP-5: Low Back (Lumbar Spine) \nPain/Coccydynia without \nNeurological Features\n 31 SP-6: Lower Extremity Pain with Neurological Features \n(Radiculopathy, Radiculitis, or Plexopathy and Neuropathy) With or \nWithout Low Back (Lumba\nr Spine) Pain\n 35 SP-7: Myelopathy\n 39 SP-8: Lumbar Spine Spondylolysis/Spondylolisthesis\n 42 SP-9: Lumbar Spinal Stenosis\n 45 SP-10: Sacro\n-Iliac (SI) Joint Pain, Inflammatory \nSpondylitis/Sacroiliitis and Fibromyalgia\n 47 SP-11: Pathological Spinal Compression Fractures\n 50 SP-12: Spinal Pain in Cancer Patients\n 52 SP-13: Spinal Can\nal/Cord Disorders (e.g. Syringomyelia)\n 53 SP-14: Spinal Deformities (e.g. Scoliosis/Kyphosis)\n 55 SP-15: Post\n-Operative Spinal Diso\nrders\n 58 SP-16: Other Imaging Studies and Procedures Related to the Spine \nImaging Guidelines\n 61 SP-17: Nuclear Medicine\n 65    "
        }
    }

我很困惑如何映射“行”,因为 elasticsearch 不支持数组。

【问题讨论】:

  • 如何使用行中的数据?
  • 基本上我们将在行中查询guildelines并返回相关的表数据
  • 是术语查询吗?我认为rows: keyword 就足够了

标签: python django elasticsearch


【解决方案1】:

无需为数组值指定任何特定映射。

如果您不定义任何显式映射,则 rows 字段将被动态添加为 text 数据类型

没有为arrays in elasticsearch 定义数据类型。您只需要确保rows 字段包含相同类型的数据


添加一个包含索引数据、搜索查询和搜索结果的工作示例

索引映射:

{
  "mappings": {
    "properties": {
      "rows": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword"
          }
        }
      }
    }
  }
}

搜索查询:

{
  "query": {
    "match": {
      "rows": "Myelopathy"
    }
  }
}

搜索结果:

"hits": [
      {
        "_index": "67581594",
        "_type": "_doc",
        "_id": "1",
        "_score": 0.28976172,
        "_source": {
          "title": "Spine Imaging Guidelines",
          "rows": [
            "Procedure Codes Associated with Spine Imaging \n3",
            "SP-1: General Guidelines \n5",
            "SP-2: Imaging Techniques \n15",
            "SP-3: Neck (Cervical Spine) Pain Without/With Neurological \nFeatures (Including Stenosis) and Trauma \n24",
            "SP-4: Upper Back (Thoracic Spine) Pain Without/With Neurological \nFeatures (Including Stenosis) and Trauma \n28",
            "SP-5: Low Back (Lumbar Spine) Pain/Coccydynia without \nNeurological Features \n31",
            "SP-6: Lower Extremity Pain with Neurological Features \n(Radiculopathy, Radiculitis, or Plexopathy and Neuropathy) With or \nWithout Low Back (Lumbar Spine) Pain \n35",
            "SP-7: Myelopathy \n39",
            "SP-8: Lumbar Spine Spondylolysis/Spondylolisthesis \n42",
            "SP-9: Lumbar Spinal Stenosis \n45",
            "SP-10: Sacro-Iliac (SI) Joint Pain, Inflammatory \nSpondylitis/Sacroiliitis and Fibromyalgia \n47",
            "SP-11: Pathological Spinal Compression Fractures \n50",
            "SP-12: Spinal Pain in Cancer Patients \n52",
            "SP-13: Spinal Canal/Cord Disorders (e.g. Syringomyelia) \n53",
            "SP-14: Spinal Deformities (e.g. Scoliosis/Kyphosis) \n55",
            "SP-15: Post-Operative Spinal Disorders \n58",
            "SP-16: Other Imaging Studies and Procedures Related to the Spine \nImaging Guidelines \n61",
            "SP-17: Nuclear Medicine \n65"
          ],
          "meta": {
            "page_no": 2,
            "page_text": "Spine Imaging \nGuidelines\n Procedure Codes Associated with Spine Imaging\n 3 SP-1: General Guidelines\n 5 SP-2: Imaging Techniques\n 15 SP-3: Neck (Cervical Spine) Pain Without/With Neurological \nFeatures (Including Stenosis) and Trauma\n 24 SP-4: Upper Back (Thoracic Spine) Pain Without/With Neurological \nFeatures (Including Stenosis) and Trauma\n 28 SP-5: Low Back (Lumbar Spine) \nPain/Coccydynia without \nNeurological Features\n 31 SP-6: Lower Extremity Pain with Neurological Features \n(Radiculopathy, Radiculitis, or Plexopathy and Neuropathy) With or \nWithout Low Back (Lumba\nr Spine) Pain\n 35 SP-7: Myelopathy\n 39 SP-8: Lumbar Spine Spondylolysis/Spondylolisthesis\n 42 SP-9: Lumbar Spinal Stenosis\n 45 SP-10: Sacro\n-Iliac (SI) Joint Pain, Inflammatory \nSpondylitis/Sacroiliitis and Fibromyalgia\n 47 SP-11: Pathological Spinal Compression Fractures\n 50 SP-12: Spinal Pain in Cancer Patients\n 52 SP-13: Spinal Can\nal/Cord Disorders (e.g. Syringomyelia)\n 53 SP-14: Spinal Deformities (e.g. Scoliosis/Kyphosis)\n 55 SP-15: Post\n-Operative Spinal Diso\nrders\n 58 SP-16: Other Imaging Studies and Procedures Related to the Spine \nImaging Guidelines\n 61 SP-17: Nuclear Medicine\n 65    "
          }
        }
      }
    ]

【讨论】:

  • @Yash 您将像 "SP-1: General Guidelines \n5" 一样查询该行中的该指南,如果该行中存在该指南,则将返回该文档?
  • 可能是那个词,也可能只是一个词,比如“脊髓病”
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-07-11
  • 1970-01-01
  • 1970-01-01
  • 2014-11-26
  • 2016-07-05
  • 2019-02-02
  • 2020-04-09
相关资源
最近更新 更多