【问题标题】:ElasticSearch river from Mongo messing up field mappings来自 Mongo 的 ElasticSearch 河弄乱了字段映射
【发布时间】:2014-08-31 00:21:54
【问题描述】:

我正在使用 Mongo、Elastic Search 和这个 River 插件:https://github.com/richardwilly98/elasticsearch-river-mongodb

我已经成功设置了所有东西,当更新 Mongo 时,河流会保持 ES 数据更新,但是河流会直接将 Mongo 文档中的所有属性复制到 ES 中,但我只想要一个小的子集那些记录。例如。如果一个 Mongo 文档有 30 个属性,所有这些属性都被放入 ES 而不是我想要的只有 5 个。我认为问题出在映射上,我已经关注了几个文档和另一个 Stack Overflow 线程 (curl -X POST -d @mapping.json + mapping not created),但它仍然不适合我。这是我正在做的事情:

我正在创建我的索引:

curl -XPOST "http://localhost:9200/mongoindex" -d @index.json

index.json:

{
  "settings" : {
      "number_of_shards" : 1
  },
  "analysis" : {
    "analyzer" : {
      "str_search_analyzer" : {
        "tokenizer" : "keyword",
        "filter" : ["lowercase"]
      },
      "str_index_analyzer" : {
         "tokenizer" : "keyword",
         "filter" : ["lowercase", "ngram"]
      }
    },
    "filter" : {
      "ngram" : {
        "type" : "ngram",
        "min_gram" : 2,
        "max_gram" : 20
      }
    }
  }
}

然后运行:

curl -XPOST "http://localhost:9200/mongoindex/listing/_mapping" -d @mapping.json

有了这个数据:

{
   "listing":{
      "properties":{
        "_all": {
          "enabled": false
        },
        "title": {
          "type": "string",
          "store": false,
          "index": "not_analyzed"
        },
        "bathrooms": {
          "type": "integer",
          "store": true,
          "index": "analyzed"
        },
        "bedrooms": {
          "type": "integer",
          "store": true,
          "index": "analyzed"
        },
        "address": {
          "type": "nested",
          "include_in_parent": true,
          "store": true,
            "properties": {
              "counrty": {
                "type":"string"
              },
              "city": {
                "type":"string"
              },
              "stateOrProvince": {
                "type":"string"
              },
              "fullStreetAddress": {
                "type":"string"
              },
              "postalCode": {
                "type":"string"
              }
            }
        },
        "location": {
          "type": "geo_point",
          "full_name": "geometry.coordiantes",
          "store": true
        }
      }
   }
}

最后创建河流:

curl -XPUT "http://localhost:9200/_river/mongoindex/_meta" -d @river.json

river.json:

{
  "type": "mongodb",
  "mongodb": {
    "db": "blueprint",
    "collection": "Listing",
    "options": {
      "secondary_read_preference": true,
      "drop_collection": true
    }
  },
  "index": {
    "name": "mongoindex",
    "type": "listing"
  }
}

毕竟在 ES 中工作的河流已被填充,但它现在是 Mongo 的逐字副本,我需要修改映射,但它只是没有生效。我错过了什么?

这就是我的地图在河流流过之后的样子......完全不是我想要的样子。

【问题讨论】:

  • 您可以再试一次吗,但在创建河流之前,请使用此命令获取映射并添加到您的问题中? curl -XGET 'localhost:9200/_mapping?pretty'
  • 我得到了预期的结果,在第二个命令之后映射是正确的。当河流被创建时,它会重置它。见第二张截图。

标签: mongodb elasticsearch elasticsearch-mongo-river


【解决方案1】:

我会将动态映射设置为 false:

未映射类型的映射的动态创建可以完全 通过将 index.mapper.dynamic 设置为 false 来禁用。

http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-dynamic-mapping.html

其他人也遇到过与您类似的问题,目前看来最好的解决方案是完全阻止 MongoDB River 动态映射:

https://github.com/richardwilly98/elasticsearch-river-mongodb/issues/75

【讨论】:

  • 我在此建议之前添加了 dynamic: false 设置,它似乎有效,但现在的问题是河流输入的文件数量是两倍。例如。 Mongo 有 451 个文档,然后运行河流后的 mongoindex 有 902 个。
【解决方案2】:

原来的问题是动态属性被排除在映射配置之外。它应该在 2 个地方,在 index.json 上,如上所示,在 mappings.json 中:

{
   "listing":{
      "_source": {
        "enabled": false
      },
      "dynamic": false,      // <--- Need to add this
      "properties":{
        "_all": {
          "enabled": false
        },
        "title": {
          "type": "string",
          "store": false,
          "index": "str_index_analyzer"
        },
        "bathrooms": {
          "type": "integer",
          "store": true,
          "index": "analyzed"
        },
        "bedrooms": {
          "type": "integer",
          "store": true,
          "index": "analyzed"
        },
        "address": {
          "type": "nested",
          "include_in_parent": true,
          "store": true,
            "properties": {
              "counrty": {
                "type":"string",
                "index": "str_index_analyzer"
              },
              "city": {
                "type":"string",
                "index": "str_index_analyzer"
              },
              "stateOrProvince": {
                "type":"string",
                "index": "str_index_analyzer"
              },
              "fullStreetAddress": {
                "type":"string",
                "index": "str_index_analyzer"
              },
              "postalCode": {
                "type":"string"
              }
            }
        },
        "location": {
          "type": "geo_point",
          "full_name": "geometry.coordiantes",
          "store": true
        }
      }
   }
}

902 docs vs 451,我认为这是我用来浏览文档的 ElasticSearch Head 插件中的一个错误。它没有重复,但有几个地方将 902 个文档显示为各种摘要。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-08-12
    • 1970-01-01
    • 2012-08-31
    • 2017-10-13
    • 2017-05-18
    • 1970-01-01
    • 1970-01-01
    • 2016-04-23
    相关资源
    最近更新 更多