# How can I do substring match without fuzzy search

**URL:** https://discuss.elastic.co/t/how-can-i-do-substring-match-without-fuzzy-search/114032
**Category:** Elasticsearch
**Created:** [January 4, 2018, 7:27am UTC](https://discuss.elastic.co/t/how-can-i-do-substring-match-without-fuzzy-search/114032 "2018-01-04T07:27:26Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![a0e775adb87d82f8fc3a](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/a0e775adb87d82f8fc3a/32/26227_2.png) [@a0e775adb87d82f8fc3a](https://discuss.elastic.co/u/a0e775adb87d82f8fc3a)
#### Post date: [January 4, 2018, 7:27am UTC](https://discuss.elastic.co/t/how-can-i-do-substring-match-without-fuzzy-search/114032/1 "2018-01-04T07:27:26Z")

</div>

I have indexed 2 columns of my table _name_ and _description_. I am using a lib to call the ES to get my result. But the result it is giving me is not what I want. I want a substring match, but it does fuzzy search. I do have 2 projects with name as "Project V.02", "Project V.011". When I search with "01", I want only 1 to come as a result, but I get both. What I need to change in my query to achieve this?

```
class Project < ApplicationRecord
  searchkick
  
  scope :search_by_keyword, ->(keyword) {
    if keyword.present?
      search keyword, fields: %i(name description)
    else
      search "*"
    end
  }

  def search_data
    {
      name: name,
      description: description,
    }
  end
end

```

Result and curl query to ES is:

```
2.4.1 :018 > Project.pluck(:name)
   (0.5ms) SELECT "projects"."name" FROM "projects"
 => ["Project V.02", "Project V.011"]
2.4.1 :019 > Project.search_by_keyword('01').each { |p| p.name }
  Project Search (9.8ms) curl http://localhost:9200/projects_development/_search?pretty -d '{"query":{"dis_max":{"queries":[{"match":{"name.analyzed":{"query":"01","boost":10,"operator":"and","analyzer":"searchkick_search"}}},{"match":{"name.analyzed":{"query":"01","boost":10,"operator":"and","analyzer":"searchkick_search2"}}},{"match":{"name.analyzed":{"query":"01","boost":1,"operator":"and","analyzer":"searchkick_search","fuzziness":1,"prefix_length":0,"max_expansions":3,"fuzzy_transpositions":true}}},{"match":{"name.analyzed":{"query":"01","boost":1,"operator":"and","analyzer":"searchkick_search2","fuzziness":1,"prefix_length":0,"max_expansions":3,"fuzzy_transpositions":true}}},{"match":{"description.analyzed":{"query":"01","boost":10,"operator":"and","analyzer":"searchkick_search"}}},{"match":{"description.analyzed":{"query":"01","boost":10,"operator":"and","analyzer":"searchkick_search2"}}},{"match":{"description.analyzed":{"query":"01","boost":1,"operator":"and","analyzer":"searchkick_search","fuzziness":1,"prefix_length":0,"max_expansions":3,"fuzzy_transpositions":true}}},{"match":{"description.analyzed":{"query":"01","boost":1,"operator":"and","analyzer":"searchkick_search2","fuzziness":1,"prefix_length":0,"max_expansions":3,"fuzzy_transpositions":true}}}]}},"size":1000,"from":0,"timeout":"11s","_source":false}'
  Project Load (0.9ms) SELECT "projects".* FROM "projects" WHERE "projects"."id" IN (2, 1)
 => [#<Project id: 2, name: "Project V.02", zipcode: "21221", timeframe: "4-6 weeks", supplier: nil, user_id: 1, created_at: "2017-12-23 10:10:40", updated_at: "2017-12-23 10:10:40", status: "in_active", description: "Lorem Ipsum is simply dummy text of the printing a...">, #<Project id: 1, name: "Project V.011", zipcode: "30333", timeframe: "4-6 weeks", supplier: nil, user_id: 1, created_at: "2017-12-23 04:25:08", updated_at: "2017-12-30 13:25:27", status: "in_active", description: "Lorem Ipsum is simply dummy text of the printing a...">]
2.4.1 :020 >

```

I tried this suggestion [https://www.reddit.com/r/rails/comments/7nupu5/basic\_searckick\_question/](https://www.reddit.com/r/rails/comments/7nupu5/basic_searckick_question/) but that didn't work.

---

<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: [February 1, 2018, 7:27am UTC](https://discuss.elastic.co/t/how-can-i-do-substring-match-without-fuzzy-search/114032/2 "2018-02-01T07:27:29Z")

</div>

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