在Elastic Search 5.2中禁用每个索引的动态映射

时间:2017-04-04 04:38:57

标签: elasticsearch

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

我认为添加'index.mapper.dynamic'应该在索引级别禁用它吗?

在这里编辑: 我也尝试将动态属性设置为'false in the type. Strangely, if I post the document then it doesn't actually update the mapping, so if check _ mapping`“filteredField”未列出,但是当我搜索文档时,filteredField已被编入索引并且存在! -

弹性版本:

{
  "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是我添加到发布文档中的字段,只是为了测试 - 它不应该在结果中。我还检查了映射,并将其动态添加到映射中。

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

{
  "_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 个答案:

答案 0 :(得分:0)

您必须在映射中"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"
        }
      }
    }
  }
}

由于