2
votes

I am trying to improve full text search functionality of our application which is based on elasticsearch. I have documents with unknown list of additional properties which should be searchable after document is indexed, but also I have list of known properties which are technical metadata, so I want to exclude these properties from full text search.

Currently this functionality is implemented using fuzzy_like_this query and this query has fields property, but you have to specify full path to all fields you want to search against. In my case it's not an option because I don't know beforehand list of fields, and I would like to specify exclude list.

I have considered to use solution suggested in this post to set index to no for these metadata fields, but it's also not an option because I need to filter by some of this fields, thus I do need to index them.

I created issue on github, which perfectly fits to what I want to have but it's still open.

Could anybody please help with any possible solution or workaround here?

1

1 Answers

2
votes

By default, everything will be analyzed for full text search. You will need to specify a mapping in order to prevent the fields from getting analyzed. The way you can do it is by send a PUT request to your index. A sample mapping may look like:

{

    "mappings": {
        "test": {
            "properties": {
                "country": {
                    "type": "string",
                    "index": "not_analyzed"
                },
                "description": {
                    "type": "string"
                },
                "modified_date": {
                    "type": "date",
                    "format": "dateOptionalTime"
                },
                "posted_date": {
                    "type": "date",
                    "format": "dateOptionalTime"
                },
                "title": {
                    "type": "string"
                }
            }
        }
    }
 }

You will need to send it to your index. E.g

curl -XPUT http://elasticsearch:9200/myindex/ -d '{MAPPING}'

Please see this link for more information. Note that, you cannot change a field once. So you will need to delete your document first and then send the mapping.