# Smart search

**URL:** https://discuss.elastic.co/t/smart-search/72263
**Category:** Elasticsearch
**Created:** [January 20, 2017, 4:51am UTC](https://discuss.elastic.co/t/smart-search/72263 "2017-01-20T04:51:01Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Umar\_Memon](https://avatars.discourse-cdn.com/v4/letter/u/c68b51/32.png) [@Umar\_Memon](https://discuss.elastic.co/u/Umar_Memon)
#### Post date: [January 20, 2017, 4:51am UTC](https://discuss.elastic.co/t/smart-search/72263/1 "2017-01-20T04:51:01Z")

</div>

Can elastic search has the feature of smart search, For example if i searches for the computer search result also retrive the content having laptop.  
Is it possible with elastic search, if so any refrence.  
I am using ES 5.X

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [January 20, 2017, 7:02am UTC](https://discuss.elastic.co/t/smart-search/72263/2 "2017-01-20T07:02:36Z")

</div>

Looks like you can do similar things by using synonyms.

But you need to provide the dictionary you want to use.

---

<div class="post-metadata">

### Author: ![Umar\_Memon](https://avatars.discourse-cdn.com/v4/letter/u/c68b51/32.png) [@Umar\_Memon](https://discuss.elastic.co/u/Umar_Memon)
#### Post date: [January 23, 2017, 5:25am UTC](https://discuss.elastic.co/t/smart-search/72263/3 "2017-01-23T05:25:05Z")

</div>

Thank you for the response,  
Can i get the path way for implementing synonyms by providing the Dictionary using the .Net Nest with Elasticsearch 5.X

Thanks in advance.

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [January 23, 2017, 8:25am UTC](https://discuss.elastic.co/t/smart-search/72263/4 "2017-01-23T08:25:46Z")

</div>

I don't write .Net / Nest code. Can't help here. Sorry.  
But may be other readers can?

---

<div class="post-metadata">

### Author: ![forloop](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/forloop/32/9021_2.png) [@forloop](https://discuss.elastic.co/u/forloop)
#### Post date: [January 23, 2017, 12:15pm UTC](https://discuss.elastic.co/t/smart-search/72263/5 "2017-01-23T12:15:34Z")

</div>

Include a text file containing your synonyms in a path that is accessible relative to the elasticsearch config directory. For this example, let's create a `computer_synonyms.txt` file in `<elasticsearch>/config/analysis` with the following content

```nohighlight
computer, laptop

```

Now, create an index with a custom analyzer with a synonym token filter that uses the synonyms file we've created

```auto
// Define a POCO type to map documents in Elasticsearch to
public class Document
{
    public string Title { get; set; }
}

var pool = new SingleNodeConnectionPool(new Uri("http://localhost:9200"));
var defaultIndex = "examples";
var connectionSettings = new ConnectionSettings(pool)
        .DefaultIndex(defaultIndex);

var client = new ElasticClient(connectionSettings);

var indexResponse = client.CreateIndex(defaultIndex, c => c
    .Settings(s => s
        .Analysis(a => a
            .TokenFilters(tf => tf
                // synonym token filter, using the synonyms file
                .Synonym("computer_synonyms_filter", stf => stf
                    .SynonymsPath("analysis/computer_synonyms.txt")
                )
            )
            .Analyzers(an => an
                // custom analyzer that uses a standard tokenizer
                // along with lowercase and our computer_synonyms token filters
                .Custom("computer_synonyms_analyzer", ca => ca
                    .Tokenizer("standard")
                    .Filters(
                        "lowercase",
                        "computer_synonyms_filter")
                )
            )
        )
    )
    .Mappings(m => m
        // map our document POCO type
        .Map<Document>(d => d
            .AutoMap()
            .Properties(p => p
                .Text(s => s
                    .Name(n => n.Title)
                    // specify our custom analyzer as the analyzer to use
                    // for the Title property
                    .Analyzer("computer_synonyms_analyzer")
                )
            )
        )
    )
);

```

With the index created, along with the custom analyzer and the mapping for our `Document` POCO type, let's index a document and then search for it

```auto
client.Index(new Document { Title = "laptop" }, i => i.Refresh(Refresh.WaitFor));

var searchResponse = client.Search<Document>(s => s
    .Query(q => q
        .Match(m => m
            .Field(f => f.Title)
            .Query("computer")
        )
    )
);

```

`searchResponse` returns the following json, demonstrating that our synonym token filter is working

```json
{
  "took" : 2,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "failed" : 0
  },
  "hits" : {
    "total" : 1,
    "max_score" : 0.46029136,
    "hits" : [
      {
        "_index" : "examples",
        "_type" : "document",
        "_id" : "AVnLQF4tcWwxFhzvdQ06",
        "_score" : 0.46029136,
        "_source" : {
          "title" : "laptop"
        }
      }
    ]
  }
}

```

---

<div class="post-metadata">

### Author: ![Umar\_Memon](https://avatars.discourse-cdn.com/v4/letter/u/c68b51/32.png) [@Umar\_Memon](https://discuss.elastic.co/u/Umar_Memon)
#### Post date: [February 3, 2017, 4:18am UTC](https://discuss.elastic.co/t/smart-search/72263/6 "2017-02-03T04:18:59Z")

</div>

Thank You for responding......It will really healpful for me.....Will implement and give the feedback.

---

<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: [March 3, 2017, 4:19am UTC](https://discuss.elastic.co/t/smart-search/72263/7 "2017-03-03T04:19:42Z")

</div>

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