不确定我的映射是否适用于 Elasticsearch

Not sure if my mapping worked in Elasticsearch

我使用这个 Elasticquent 包在我的 Laravel 应用中使用 ES。

在索引我的数据库之前,我的映射看起来像这样:

'ad_title' => [
            'type' => 'string',
            'analyzer' => 'standard'
        ],
        'ad_type' => [
            'type' => 'integer',
            'index' => 'not_analyzed'
        ],
        'ad_type' => [
            'type' => 'integer',
            'index' => 'not_analyzed'
        ],
        'ad_state' => [
            'type' => 'integer',
            'index' => 'not_analyzed'
        ],

但是当我执行 API 调用 _mapping? 之后

我的映射如下所示:

"testindex": {
        "mappings": {
            "ad_ad": {
                "properties": {
                    "ad_city": {
                        "type": "integer"
                    },
                    "ad_id": {
                        "type": "long"
                    },
                    "ad_state": {
                        "type": "integer"
                    },
                    "ad_title": {
                        "type": "string",
                        "analyzer": "standard"
                    },
                    "ad_type": {
                        "type": "integer"
                    },

之后我是否应该能够在映射中看到 'index' => 'not_analyzed'?还是 'index' => 'not_analyzed' 之后不显示在地图结构中?

你是对的,映射没有得到应用。如果应用正确,您会在映射 API 中看到 not_analyzed。

确保在写入任何数据之前应用映射。我们在应用程序启动时应用映射以验证映射始终正确并应用任何映射更新。

以下是如何应用映射的示例:

PUT hilden1

PUT hilden1/type1/_mapping
{
  "properties": {
    "regular": {
      "type": "string"
    },
    "indexSpecified": {
      "type": "string",
      "index": "not_analyzed"
    }
  }
}

验证映射使用 GET api

GET hilden1/type1/_mapping

您应该看到字段 "regular" 仅指定了它的类型,而 "indexSpecified" 被列为 not_analyzed。这是我的机器 运行 ES 1.4.4

的输出
{
   "hilden1": {
      "mappings": {
         "type1": {
            "properties": {
               "indexSpecified": {
                  "type": "string",
                  "index": "not_analyzed"
               },
               "regular": {
                  "type": "string"
               }
            }
         }
      }
   }
}