0

我正在使用 Mongo、Elastic Search 和这条河插件: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

索引.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

河流.json:

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

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

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

ES映射

在此处输入图像描述

4

2 回答 2

0

我会将动态映射设置为 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

于 2014-07-09T22:04:11.720 回答
0

原来问题是动态属性被排除在映射配置之外。它应该在 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 文档显示为各种摘要。

于 2014-07-10T18:25:13.663 回答