当前位置: 首页 > 知识库问答 >
问题:

在弹性搜索5.2中禁用每个索引的动态映射

柳德义
2023-03-14

我正在尝试禁用弹性搜索索引的动态映射器。下面是我通过Kibana控制台进行测试的一系列查询。

我想添加“index.mapper.dynamic”应该会在索引级别禁用它,对吧?

{
  "name": "DpVBoAZ",
  "cluster_name": "elasticsearch",
  "cluster_uuid": "RX6axsbOTMatorw7s5AOXQ",
  "version": {
    "number": "5.2.0",
    "build_hash": "24e05b9",
    "build_date": "2017-01-24T19:52:35.800Z",
    "build_snapshot": false,
    "lucene_version": "6.4.0"
  },
  "tagline": "You Know, for Search"
}

但是最终的GET返回这个文档,注意filteredfield是我添加到posted文档中的一个字段,只是为了测试--它不应该在结果中。我还检查了映射,它被动态添加到映射中。

我的创建索引查询有什么问题??

{
  "_index": "meu_locations",
  "_type": "location",
  "_id": "12345",
  "_version": 2,
  "found": true,
  "_source": {
    "__v": 0,
    "address1": "30 Mort Street",
    "email": "Braddon.Manager@stationeryhub.com.au",
    "faxNumber": "(02) 6122 0070",
    "geo": {
      "location": {
        "lon": 149.1317,
        "lat": -35.27433
      },
      "autogeocode": false
    },
    "identifier": "sample-store",
    "phoneNumber": "(02) 6122 0000",
    "postCode": "2612",
    "state": "ACT",
    "suburb": "Braddon",
    "title": "Hello New Title",
    "filteredField": "Hello There",
    "urlToken": "sample-store",
    "status": "Active",
    "country": "AU",
    "id": "Skcyxox6x"
  }
}

搜索查询

DELETE meu_locations

PUT meu_locations
{
  "settings": {
    "index.mapper.dynamic": false,
    "index.mapping.total_fields.limit": 2000,
    "analysis": {
      "filter": {
        "email": {
          "type": "pattern_capture",
          "preserve_original": 1,
          "patterns": [
            "([^@]+)",
            "(\\p{L}+)",
            "(\\d+)",
            "@(.+)",
            "([^-@]+)"
          ]
        }
      },
      "analyzer": {
        "case_insensitive_sort": {
          "tokenizer": "keyword",
          "filter": [
            "lowercase"
          ]
        },
        "email": {
          "tokenizer": "uax_url_email",
          "filter": [
            "email",
            "lowercase",
            "unique"
          ]
        }
      }
    }
  },
  "mappings": {
    "location": {
      "dynamic": false,
      "properties": {
        "title": {
          "type": "keyword"
        },
        "identifier": {
          "type": "keyword",
          "index": "not_analyzed"
        },
        "address1": {
          "type": "text"
        },
        "address2": {
          "type": "text"
        },
        "state": {
          "type": "keyword"
        },
        "suburb": {
          "type": "text"
        },
        "postCode": {
          "type": "keyword"
        },
        "country": {
          "type": "keyword"
        },
        "phoneNumber": {
          "type": "keyword"
        },
        "type": {
          "type": "keyword",
          "index": "not_analyzed"
        },
        "geo": {
          "properties": {
            "location": {
              "type": "geo_point"
            },
            "autogeocode": {
              "type": "boolean"
            }
          }
        },
        "services": {
          "properties": {
            "specialOrder": {
              "type": "boolean"
            },
            "assembleIt": {
              "type": "boolean"
            },
            "wifi": {
              "type": "boolean"
            },
            "officeFitout": {
              "type": "boolean"
            },
            "deliverIt": {
              "type": "boolean"
            },
            "techServices": {
              "type": "boolean"
            },
            "parking": {
              "type": "boolean"
            },
            "courtesyTrailer": {
              "type": "boolean"
            },
            "extraCover": {
              "type": "boolean"
            }
          }
        },
        "updatedAt": {
          "type": "date",
          "format": "strict_date_optional_time||epoch_millis"
        },
        "createdAt": {
          "type": "date",
          "format": "strict_date_optional_time||epoch_millis"
        },
        "publishDate": {
          "type": "date",
          "format": "strict_date_optional_time||epoch_millis"
        },
        "expiryDate": {
          "type": "date",
          "format": "strict_date_optional_time||epoch_millis"
        },
        "status": {
          "type": "keyword"
        }
      }
    }
  }
}

PUT meu_locations/location/12345
{
  "__v": 0,
  "address1": "30 Mort Street",
  "email": "Braddon.Manager@stationeryhub.com.au",
  "faxNumber": "(02) 6122 0070",
  "geo": {
    "location": {
      "lon": 149.1317,
      "lat": -35.27433
    },
    "autogeocode": false
  },
  "identifier": "sample-store",
  "phoneNumber": "(02) 6122 0000",
  "postCode": "2612",
  "state": "ACT",
  "suburb": "Braddon",
  "title": "Hello New Title",
  "filteredField": "Hello There",
  "urlToken": "sample-store",
  "status": "Active",
  "country": "AU",
  "id": "Skcyxox6x"
}

GET meu_locations/location/12345

共有1个答案

莫英卓
2023-03-14

您必须在映射中“dynamic”:“strict”才能禁用索引的动态映射。

您将需要修改您的设置的映射部分。

PUT meu_locations2
{
  "settings": {
    "index.mapping.total_fields.limit": 2000,
    "analysis": {
      "filter": {
        "email": {
          "type": "pattern_capture",
          "preserve_original": 1,
          "patterns": [
            "([^@]+)",
            "(\\p{L}+)",
            "(\\d+)",
            "@(.+)",
            "([^-@]+)"
          ]
        }
      },
      "analyzer": {
        "case_insensitive_sort": {
          "tokenizer": "keyword",
          "filter": [
            "lowercase"
          ]
        },
        "email": {
          "tokenizer": "uax_url_email",
          "filter": [
            "email",
            "lowercase",
            "unique"
          ]
        }
      }
    }
  },
  "mappings": {
    "location": {
      "dynamic": false,
      "properties": {
        "title": {
          "type": "keyword"
        },
        "identifier": {
          "type": "keyword",
          "index": "not_analyzed"
        },
        "address1": {
          "type": "text"
        },
        "address2": {
          "type": "text"
        },
        "state": {
          "type": "keyword"
        },
        "suburb": {
          "type": "text"
        },
        "postCode": {
          "type": "keyword"
        },
        "country": {
          "type": "keyword"
        },
        "phoneNumber": {
          "type": "keyword"
        },
        "type": {
          "type": "keyword",
          "index": "not_analyzed"
        },
        "geo": {
          "properties": {
            "location": {
              "type": "geo_point"
            },
            "autogeocode": {
              "type": "boolean"
            }
          }
        },
        "services": {
          "properties": {
            "specialOrder": {
              "type": "boolean"
            },
            "assembleIt": {
              "type": "boolean"
            },
            "wifi": {
              "type": "boolean"
            },
            "officeFitout": {
              "type": "boolean"
            },
            "deliverIt": {
              "type": "boolean"
            },
            "techServices": {
              "type": "boolean"
            },
            "parking": {
              "type": "boolean"
            },
            "courtesyTrailer": {
              "type": "boolean"
            },
            "extraCover": {
              "type": "boolean"
            }
          }
        },
        "updatedAt": {
          "type": "date",
          "format": "strict_date_optional_time||epoch_millis"
        },
        "createdAt": {
          "type": "date",
          "format": "strict_date_optional_time||epoch_millis"
        },
        "publishDate": {
          "type": "date",
          "format": "strict_date_optional_time||epoch_millis"
        },
        "expiryDate": {
          "type": "date",
          "format": "strict_date_optional_time||epoch_millis"
        },
        "status": {
          "type": "keyword"
        }
      }
    }
  }
}

谢谢

 类似资料:
  • 我有大量相同类型的实体,每个实体都有大量属性,并且我只有以下两种选择来存储它们: 将每个项存储在索引中并执行多索引搜索 将所有enties存储在单个索引中,并且只搜索1个索引。 一般而言,我想要一个时间复杂度之间的比较搜索“N”实体与“M”特征在上述每一种情况!

  • 我刚加入弹性搜索公司。而不知道如何在JSON请求中对索引和an类型发出正确的请求?(所以我不想像localhost:9200/myindex/mytype/_search那样在URL中使用索引和类型,而是向localhost:9200/_search发出JSON请求) 我试过这样的东西。但我得到的结果是'AAA'索引而不是'BBB'索引。如何只从bbb索引得到结果或者根本没有结果?

  • 我们使用弹性搜索动态映射,java文件如下所示。 我们使用每60分钟运行一次的调度程序从数据库中获取数据并添加到索引中。 问题是数据库中已删除的记录。这些记录不会从索引中删除,而是成为孤立记录。 我遇到了“ttl”属性,并寻找一种方法将其添加到索引中,以便在ttl时间之后删除孤儿记录。 如果不将ttl添加到每个索引中,它是否应该是所有文档的通用级别?如果是,是否应该为每次调度运行设置此设置? 谢谢

  • 我已经将弹性搜索1.7.1与spring应用程序集成在一起。我有一个cron作业,它在每次运行时更新弹性搜索的索引。我遵循了github上的各种示例代码来使其工作。首先,我为索引目的自动连接了ElasticSearchOperations: 然后以以下方式执行内部循环索引 当我第一次运行它时,它就像预期的那样工作。我已经在config文件夹中的elasticsearch.yml中将cluster重

  • 我正在学习弹性搜索,还有很多东西我没有得到,但有一件事我不知道(或发现所有的)是什么时候使用一个索引,什么时候使用更多的索引。部分原因是我不知道弹性搜索索引到底是什么。 您能解释一下什么是弹性搜索索引吗?什么时候应该只对所有数据使用一个索引?什么时候应该将数据拆分为多个索引? 奖励点/或者,我如何判断何时需要将我的数据拆分为多个索引,然后,我应该如何决定如何将数据拆分为新的索引?

  • 当我运行curl-X GET“elastic01:9200/_cat/index?v”时,我观察到我的一个索引的健康值为红色 我检查了集群的运行状况,即使是红色的 如何将elasticsearch索引健康状态从红色变为绿色。