elasticsearch 映射 预期在字段[name]上为属性[fields]进行映射,但得到的却是一个java.lang.String类。

问题描述 投票:0回答:1

这是我的数据,它是基于一个模式,我需要生成映射在ES上做索引。我的背景与ES是不多,但我认为我得到了它,直到我试过,但失败了,不能找到正确的答案在网上... ...

{
  "@context": {
    "schema": "http://schema.org/",
    "outbreak": "https://discovery.biothings.io/view/outbreak/"
  },
  "@type": "outbreak:Publication",
  "keywords": [
    "COVID-19",
    "City lockdown",
    "Epidemic",
    "Governmental action",
    "Individual reaction",
    "Mathematical modelling"
  ],
  "author": [
    {
      "@type": "outbreak:Person",
      "affiliation": [
        {
          "@type": "outbreak:Organization",
          "name": "Department of Applied Mathematics, Hong Kong Polytechnic University, Hong Kong, China. Electronic address: [email protected]."
        }
      ],
      "familyName": "He",
      "givenName": "Daihai",
      "name": "Daihai He"
    }
  ],
  "publicationType": [
    "Journal Article"
  ],
  "_id": "pmid32145465",
  "curatedBy": {
    "@type": "schema:WebSite",
    "name": "litcovid",
    "url": "https://www.ncbi.nlm.nih.gov/research/coronavirus/publication/32145465"
  },
  "name": "A conceptual model for the coronavirus disease 2019 (COVID-19) outbreak in Wuhan, China with individual reaction and governmental action.",
  "identifier": "32145465",
  "pmid": "32145465",
  "abstract": "The ongoing coronavirus disease 2019 (COVID-19) outbreak, emerged in Wuhan, China in the end of 2019, has claimed more than 2600 lives as of 24 February 2020 and posed a huge threat to global public health. The Chinese government has implemented control measures including setting up special hospitals and travel restriction to mitigate the spread. We propose conceptual models for the COVID-19 outbreak in Wuhan with the consideration of individual behavioural reaction and governmental actions, e.g., holiday extension, travel restriction, hospitalisation and quarantine. We employe the estimates of these two key components from the 1918 influenza pandemic in London, United Kingdom, incorporated zoonotic introductions and the emigration, and then compute future trends and the reporting ratio. The model is concise in structure, and it successfully captures the course of the COVID-19 outbreak, and thus sheds light on understanding the trends of the outbreak.",
  "license": "Copyright © 2020 The Authors. Published by Elsevier Ltd.. All rights reserved.",
  "journalName": "International journal of infectious diseases : IJID : official publication of the International Society for Infectious Diseases",
  "journalAbbreviation": "Int. J. Infect. Dis.",
  "issueNumber": "1878-3511",
  "doi": "S1201-9712(20)30117-X",
  "url": "https://www.doi.org/S1201-9712(20)30117-X",
  "datePublished": "2020-03-04",
  "dateModified": "2020-02-26"
}

这是我目前的映射。

{
                'fields':{
                    'type': 'string'
                },
                'abstract': {
                    'type': 'text'
                },
                'pmid': {
                    'type': 'integer'
                },
                'author': {
                    'type': 'nested',
                    'properties': {
                        'name':{
                            'type': 'text'
                        },
                        'givenName':{
                            'type': 'text'
                        },
                        'familyName':{
                            'type': 'text'
                        },
                        'affiliation':{
                            'type': 'nested',
                            'properties': {
                                'name':{
                                    'type': 'text'
                                }
                            }
                        }
                    }
                },
                'isBasedOn': {
                    'type': 'text'
                },
                'funding': {
                    'type': 'nested',
                    'properties': {
                        'funder':{
                            'type': 'nested',
                            'properties':{
                                'name': 'text'
                            }
                        },
                        'identifier':{
                            'type': 'text'
                        }
                    }
                },
                'license': {
                    'type': 'text'
                },
                'keywords': {
                    'normalizer': 'keyword_lowercase_normalizer',
                    'type': 'keyword',
                    'copy_to': ['all']
                },
                'publicationType': {
                    'normalizer': 'keyword_lowercase_normalizer',
                    'type': 'keyword',
                    'copy_to': ['all']
                },
                'name': {
                    'type': 'text'
                },
                'journalName': {
                    'type': 'text'
                },
                'identifier': {
                    'type': 'text'
                },
                'doi': {
                    'type': 'text'
                },
                'datePublished': {
                    'type': 'date'
                },
                'dateModified': {
                    'type': 'date'
                },
                'issueNumber': {
                    'type': 'text'
                }
         }

我的数据中没有 "字段 "这个字段 所以我不知道这是什么意思 "名称 "是一个简单的字符串。

我试过这样做,也包括 "映射":{"属性":{...}},但也失败了。有什么好的建议吗?

python elasticsearch mapping
1个回答
0
投票

你的映射有两个问题

  1. 字符串,它不再是有效的数据类型,请使用文本。

  2. 'properties':{'name': 'text'}应该是 "name":{"type": "text"}。

你使用的是归一化器,我不知道你的要求,所以检查一下你是需要归一化器还是分析器。

更正后的图谱

"fields": {
        "type": "text"
      },
      "abstract": {
        "type": "text"
      },
      "pmid": {
        "type": "integer"
      },
      "author": {
        "type": "nested",
        "properties": {
          "name": {
            "type": "text"
          },
          "givenName": {
            "type": "text"
          },
          "familyName": {
            "type": "text"
          },
          "affiliation": {
            "type": "nested",
            "properties": {
              "name": {
                "type": "text"
              }
            }
          }
        }
      },
      "isBasedOn": {
        "type": "text"
      },
      "funding": {
        "type": "nested",
        "properties": {
          "funder": {
            "type": "nested",
            "properties": {
              "name": {
                "type": "text"
              }
            }
          },
          "identifier": {
            "type": "text"
          }
        }
      },
      "license": {
        "type": "text"
      },
      "keywords": {
        "normalizer": "keyword_lowercase_normalizer",
        "type": "keyword",
        "copy_to": [
          "all"
        ]
      },
      "publicationType": {
        "normalizer": "keyword_lowercase_normalizer",
        "type": "keyword",
        "copy_to": [
          "all"
        ]
      },
      "name": {
        "type": "text"
      },
      "journalName": {
        "type": "text"
      },
      "identifier": {
        "type": "text"
      },
      "doi": {
        "type": "text"
      },
      "datePublished": {
        "type": "date"
      },
      "dateModified": {
        "type": "date"
      },
      "issueNumber": {
        "type": "text"
      }


0
投票

尽量用文字或关键词代替 string 用于外地 fields

string在Elasticsearch中不是一个有效的数据类型。你可以使用关键字或文本

  • 文本数据类型

    用于索引全文值的字段,如电子邮件的正文或产品的描述。这些字段是经过分析的,也就是说,在被索引之前,它们会通过分析器将字符串转换成一个单独的术语列表。分析过程允许Elasticsearch在每个完整的文本字段中搜索单个词。文本字段不用于排序,也很少用于聚合(尽管重要的文本聚合是一个明显的例外)。

  • 关键字数据类型

    用于索引结构化内容的字段,如ID、电子邮件地址、主机名、状态码、邮政编码或标签。

来源于: https:/www.elastic.coguideenelasticsearchreferencecurrentmapping-types.html

© www.soinside.com 2019 - 2024. All rights reserved.