简体   繁体   中英

Index only some fields in ElasticSearch from mongodb

I'm using elasticsearch 0.90.2 and elasticsearch-river-mongodb 1.7.0 to retrieve data from mongodb's oplog. In the collection I'm trying to index I have thousands of structured records, let's just named them 'field1', 'field2', 'field3'...'field10'

Is there a way to index only 'field1' and 'field2' ? Does it matter if these as strings or date objects ?

Thanks

I never used river plugins, but one thing that I know is you can control index upon fields through mapping or template. For each field, you can specify the property "index", in mapping or template, to three different options: analyzed, not_analyzed, no. This is the official documentation.

Set to analyzed for the field to be indexed and searchable after being broken down into token using an analyzer. not_analyzed means that its still searchable, but does not go through any analysis process or broken down into tokens. no means that it won't be searchable at all (as an individual field; it may still be included in _all). Setting to no disables include_in_all. Defaults to analyzed.

If you want your field still be searchable, go with "not_analyzed", otherwise "no". The type of fields should not matter.

Here is a mapping example from official website

{
    "tweet" : {
        "properties" : {
            "user" : {"type" : "string", "index" : "not_analyzed"},
            "message" : {"type" : "string", "null_value" : "na"},
            "postDate" : {"type" : "date"},
            "priority" : {"type" : "integer"},
            "rank" : {"type" : "float"}
        }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM