# Even searching with elasticsearch I wasn't able to find a solution

**URL:** https://discuss.elastic.co/t/even-searching-with-elasticsearch-i-wasnt-able-to-find-a-solution/95594
**Category:** Elasticsearch
**Created:** [August 2, 2017, 6:42pm UTC](https://discuss.elastic.co/t/even-searching-with-elasticsearch-i-wasnt-able-to-find-a-solution/95594 "2017-08-02T18:42:29Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![aletaschner](https://avatars.discourse-cdn.com/v4/letter/a/aca169/32.png) [@aletaschner](https://discuss.elastic.co/u/aletaschner)
#### Post date: [August 2, 2017, 6:42pm UTC](https://discuss.elastic.co/t/even-searching-with-elasticsearch-i-wasnt-able-to-find-a-solution/95594/1 "2017-08-02T18:42:29Z")

</div>

### Hello!

I'm trying to build a search engine to an e-commerce but failing to get the relevance I need. I've read tutorials [all over the internet](https://www.elastic.co/guide/en/elasticsearch/guide/current/_index_time_search_as_you_type.html) but could not manage to implement the way it fits this special case needs.

First, let me explain how to I want it to work: as the user type I want to have relevant suggestions of products based on the user query.

I actually happen to have a [perfect example](http://lojadomecanico.com.br/) of it working the way I wanted (and with a little extra). This is how I want it to work (minus the suggestion which is not needed):

 ![perfect](https://image.ibb.co/h5OrEk/img_01.png)

And when I type in "furad bosc" it still finds the results as shown bellow:

 ![wow](https://image.ibb.co/kBLGfQ/img_02.png)

* * *

The index I have so far looks like this:

```json
{
    "settings": {
        "number_of_shards": 1, 
        "analysis": {
            "filter": {
                "autocomplete_filter": { 
                    "type": "edge_ngram",
                    "min_gram": 3,
                    "max_gram": 25
                }
            },
            "analyzer": {
                "autocomplete": {
                    "type": "custom",
                    "tokenizer": "standard",
                    "filter": [
                        "lowercase",
                        "autocomplete_filter",
                        "asciifolding"
                    ]
                }
            }
        }
    },
    "mappings": {
      "products": {
        "properties": {
          "name": {"type": "text", "analyzer": "autocomplete", "search_analyzer": "standard"},
          "description": {"type": "text"},
          "price": {"type": "double"},
          "product_id": {"type": "integer"},
          "image": {"type": "text"},
          "quantity": {"type": "integer"},
          "width": {"type": "float"},
          "length": {"type": "float"},
          "height": {"type": "float"},
          "weight": {"type": "float"},
          "model": {"type": "text"},
          "name_suggester": {"type": "completion", "analyzer": "autocomplete"}
        }
      }
    }
}

```

Disclaimer: the other fields (weight, width...) are for future implementations.

As for searching, I have used multiple combination of queries, the closest I got to the desired result is this one:

```json
 {
  "query": {
    "bool": {
      "should": [
          {"match_phrase_prefix": {"name^25": "furadeira bosch"} },
          {"term": {"name^2": "furadeira bosch"} }
        ],
      "must": {
        "query_string": {
            "query" : "furadeira bosch",
            "fields" : [
                "name^18",
                "model",
                "manufacturer^10"
                ]
            }
        }
    }
  }
}

```

But the results I get fail in scoring the way I wanted to:

 ![if only this would work](https://image.ibb.co/k0Htuk/Captura_de_tela_de_2017_08_02_15_34_30.png)

* * *

Now is when I ask. What am I doing wrong and how do I calculate the score correctly?

PS: I'm sorry for the bad english 😕

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [August 30, 2017, 6:42pm UTC](https://discuss.elastic.co/t/even-searching-with-elasticsearch-i-wasnt-able-to-find-a-solution/95594/2 "2017-08-30T18:42:38Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
