1

What I need is, elastic should search in multiple fields and return data by field priority.

For example: For the search string obil hon, elastic should search in fields[title, description, modelCaption] and return data when at first it finds Mobile Phone in Title field, then in other fields.

Query I use:

{
  "from": 0,
  "query": {
    "bool": {
      "must": [
        {
          "query_string": {
            "default_operator": "or",
            "fields": [
              "title^5",
              "description",
              "modelCaption",
              "productFeatureValues.featureValue",
              "productFeatureValues.featureCaption"
            ],
            "query": "*obil* *hone*"
          }
        }
      ]
    }
  },
  "size": 16
}

Any suggestions?

Thanks!

1 Answer 1

1

You can simply use the multi-match query to query multiple fields and it supports boosting a particular field like a title in your case and different operators like OR in your case.

Sample ES query for your use case:

{
  "query": {
    "multi_match" : {
      "query" : "mobile phones",
      "fields" : [ "title^5", "description","modelCaption","productFeatureValues.featureVal"],
      "fuzziness" : "AUTO" --> Adding fuzziness to query
    }
  }
}

Here title filed is boosted by factor 5, hence if mobile phones match in title field then it would be scored higher.

Also please note, you are using wild-card in your query string which is very costly so it's better to avoid them if you can.

EDIT: Based on OP comments, included fuzziness parameter AUTO in query for better results

Sign up to request clarification or add additional context in comments.

6 Comments

Thank you for your answer. I have a task that searching should work on uncompleted words, like "obile" or "hone", that's why I need query that supports that kind of search. in multi_match query I cant achieve this
@AlexanderMchedlishvili, that's a different requirement given in your question :-) , btw match query is analyzed query and it can give you results for uncompleted words given you have n-grams analyzer for these fields :-)
My native language is not supported in Elasticsearch. So, I need a way to achieve this without language analyzer
ngram is not a language analyzer elastic.co/guide/en/elasticsearch/reference/current/… please have a look, I can provide you working example if you provide some sample documents and expected results
@AlexanderMchedlishvili did you get a chance to go through my latest comment, please follow-up on your questions in order to get the help from community
|

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.