1

I am doing full text search with ElasticSearch. I am using Query String Query. I am doing search with Multi Field feature.

My query looks like below:

 {
    "query": {
         "query_string": {
            "fields": [
                "field1^5",
                "field2^5",
                "field3^1",
                "field4^1",
                ...................
                ...................
            ],
            "query": "....",
            "default_operator": "OR",
            "analyzer": "standard"
        }
    }
 }

I have more than 30 fields in my collection. For my requirement, I need to ensure that fieldA, fieldB need to be searched first. Hence these fields will have higher priority. Other fields all have low and equal priority.

So, is there some way where I don't have to specify all the field names in the query. I only want to specify those fields that have higher priority i.e fieldA , fieldB. But, the searching should be performed on all fields based on priority order.

How could I achieve this ?

5
  • Didn't understand your question. @oblivion Commented Apr 27, 2017 at 9:28
  • @DivyeshGausvami In a nutshell, I want to perform full text search on multiple fields. Among those fields, two of them have very high priority and they need to be matched first. So, in the query, I want to specify those 2 fields only by giving them higher boost value.If those 2 fields do not match the query, then only other fields need to be matched. So here, do I always need to specify all the fields in the query ? Is there some way where I dont have to list all the low priority fields in the query ? Commented Apr 27, 2017 at 9:37
  • { "query":{ "multi_match" : { "query": "searching string", "fields": [ "field1", "field2",... ,"fieldN"] } } } This might be helpful to you? am i right ? Commented Apr 27, 2017 at 9:41
  • Yes, but that is the solution that I already have.With this approach, I need to put all 30 fields in my query. But only fields: "fieldA" and "fieldB" are of higher priority. So, I only want to keep "field1" and "field2" in the query. So, I am looking for a way if this is possible. Commented Apr 27, 2017 at 9:46
  • @oblivion Did you try _all field? Where you can have all low priority fields included in _all field. Commented Apr 27, 2017 at 10:15

1 Answer 1

2

Try with this . Tested in my system ,its working for me :-

 {
    "query": {
         "query_string": {
            "fields": [
                "field1^5",
                "field2^5",
                "_all",
            ],
            "query": "....",
            "default_operator": "OR",
            "analyzer": "standard"
        }
    }
 }
Sign up to request clarification or add additional context in comments.

3 Comments

It works. Thanks a lot !! One more thing I want to ask is that do I need to assign a priority to _all as well, such as : "_all^1" ?
No need . According to elastic search doc - "boost - Sets the boost value of the query. Defaults to 1.0." elastic.co/guide/en/elasticsearch/reference/current/…
can i do the same with NEST , as i have a similar issue using the QueryString with multiple fields

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.