【问题标题】:Not sure if my mapping worked in Elasticsearch不确定我的映射是否在 Elasticsearch 中有效
【发布时间】:2015-04-29 00:07:45
【问题描述】:

我正在使用 ES 和我的 Laravel 应用程序使用这个 Elasticquent 包。

在索引数据库之前,我的映射如下所示:

'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?pretty 之后

我的映射如下所示:

"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' 之后没有显示在地图结构中?

【问题讨论】:

    标签: php mysql apache laravel elasticsearch


    【解决方案1】:

    你是对的,映射没有被应用。如果应用正确,您会在映射 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"
                   }
                }
             }
          }
       }
    }
    

    【讨论】:

    • 这写在文档的任何地方吗?我被告知 index : not_analyzed 在进行 ?pretty api 调用时不应该出现。并且只有 Analyzer : x 应该是可见的。而那个出现在我上面的例子中 - “analyzer”:“standard”
    • GET 映射 API 将显示您的索引或类型的当前映射。 ?pretty 部分只是格式化 json,我不相信它会改变返回的结构。
    • 好吧,我照你说的做了。而且我在日志中看不到任何内容。所以不知道为什么 'index' => 'not_analyzed' 不会出现:/
    • 我包含了您可以在 Sense 中使用的示例代码,希望有助于澄清。
    • 非常感谢!奇怪的是它不会将 not_analyzed 应用到我的映射中。我也不能在我的日志中出现错误/警告。我会尝试询问其他一些人(使用与我相同的包)他们是否尝试过应用 not_analyzed
    猜你喜欢
    • 2016-06-21
    • 1970-01-01
    • 2018-06-25
    • 1970-01-01
    • 1970-01-01
    • 2014-09-20
    • 1970-01-01
    • 1970-01-01
    • 2014-04-12
    相关资源
    最近更新 更多