randomuser
randomuser

Reputation: 1221

Elastic Search Custom scoring on mobile products

I'm using elastic search 2.3 I've stored all the mobile products attribute-wise in ES after removing all stopwords (e.g. with, extra, etc)

Sample schema for "Micromax Canvas Doodle 4 white with 8 GB ram and 8gb internal memory":

"_source": {
   "internal_mem": "8 GB",
   "color": "White",
   "brand": "Micromax",
   "ram": "8 GB",
   "model": "Canvas Doodle 4"
}

ES has thousands of mobile name with these features. Now, I need to do search on these products. For searching, I do have all the products broken down in attributes. So, a search for "canvas doodle 4 gb" will be:

{
    "query": {
        "bool": {
            "should": [{
                "match": {
                    "model": {
                        "query": "canvas^4 doodle",
                        "boost": 2
                    }
                }
            }, {
                "match": {
                    "internal_mem": {
                        "query": "4 GB",
                        "boost": 0.2
                    }
                }
            }]
        }
    }
}

Result I want:

  1. All products of "canvas doodle 4g" or "canvas doodle" first (sorted by score)
  2. Then, products having "canvas"
  3. then "4g"

Rules I've made:

  1. Model, Brand should have higher priorities as compared to other three
  2. First word in model/brand should have more importance. e.g. Iphone, canvas etc.

Issues:

  1. Should I use this query or should I go for function_score query (I need custom score as well)?

  2. How to avoid search results for "4" in model? e.g. "4", "mini", "3g", "4g" Should I disable IDF so that such results can be avoided?

  3. Give priorities to first word on model/brand? (assuming they are more important e.g. "canvas" in canvas doodle 3")

  4. Recommended values of "boost" for different attributes?

Open to any kind of suggestions/improvements. Please suggest.

Upvotes: 0

Views: 75

Answers (1)

Lijo Abraham
Lijo Abraham

Reputation: 881

Please try the following query .

{
  "query": {
    "filtered": {
        "query": {
            "bool": {
                "should": [{
                    "multi_match": {
                        "query": "canvas doodle 4",
                        "fields": ["model"],
                        "operator": "and"
                    }
                }, {
                    "multi_match": {
                        "query": "canvas doodle 4",
                        "fields": ["model"],
                        "type": "phrase_prefix"
                    }
                }, {
                    "multi_match": {
                        "query": "canvas doodle 4",
                        "fields": ["model"],
                        "type": "phrase"
                    }
                }]
            }
        }
    }
}

This will work like it will check for canvas,doodle and 4 , then phrase prefix then phrase queries.

Upvotes: 0

Related Questions