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


(林静云 ) #1

Hello, This is my example data about event or meeting organization.

I want to perform searching like "Songkarn holiday in Bangkok" and Elasticsearch will know automatically that "in [Bangkok]" is it mean my location fields then will try to use BoolQuery between eventDetail and location.

In the programming perhaps I can use if-else or some sort like that to filter manaully but in the Elasticsearch does it have any way to do something like this ? maybe writing some script to Elasticsearch ? I have read about machine learning in elasticsearch but I think maybe it too over-engineering ? (ofcourse if it must be the way like that I also want to try it :slight_smile:

Thank you in advance !!!


(Gabriel Tessier) #2

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.