How to make Elasticsearch can search from another field when have some specific keyword

Hi,

How about always searching in all your fields and put weight to prioritize.

Check about query string with muti-fields

https://www.elastic.co/guide/en/elasticsearch/reference/7.0/query-dsl-query-string-query.html#_multi_field

{
    "query": {
        "query_string" : {
            "fields" : ["eventDetail^2", "location^5"],
            "query" : "Songkarn holiday in Bangkok"
        }
    }
}

If it hit it will return the one with Bankok in location and title, then the one with only bankok in location then the one with bankok in eventDetail.

you also need to add a bool should around and some term or match to hit more results.

2 Likes