# How to search a contraction word?

**URL:** <https://discuss.elastic.co/t/how-to-search-a-contraction-word/145731>\
**Category:** Elasticsearch\
**Created:** [August 23, 2018, 12:54pm UTC](https://discuss.elastic.co/t/how-to-search-a-contraction-word/145731 "2018-08-23T12:54:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Masoumeh\_Shavikloo](https://avatars.discourse-cdn.com/v4/letter/m/a8b319/32.png) [@Masoumeh\_Shavikloo](https://discuss.elastic.co/u/Masoumeh_Shavikloo)\
**Post date:** [August 23, 2018, 12:54pm UTC](https://discuss.elastic.co/t/how-to-search-a-contraction-word/145731/1 "2018-08-23T12:54:20Z")

</div>

I would like search text contains of words like **I'm** or **you're** and so on using Elasticsearch. It probably should be used synonym token filter. At index time I used below code:

```
'analyzer' => [
	'default' => [
		'type' => 'custom',
		'tokenizer' => 'standard',
		'filter' => ['standard', 'lowercase', 'Snowball_filter', 'synonym_filter']
	],
	'search_analyzer' => [
		'type' => 'custom',
		'tokenizer' => 'standard',
		'filter' => ['standard', 'lowercase', 'Snowball_filter', 'synonym_filter']
	]
],
'filter' => [
	'Snowball_filter' => [
		'type' => 'snowball',
		'language' => 'English'
	],
	"synonym_filter" => [
		"type" => "synonym",
		"synonyms" => ["I'm,I am => I'm ","you're , you are => you're"]
	]
]

```

Now, suppose I have four documents:

1- I am a student.  
2- I'm a student.  
3- there are students.  
4- Am I a student?

And I use query like below:

```
[
	"match_phrase" => [
		"body" => [
			"query" => $q,
			"analyzer" => 'search_analyzer',
			"boost" => 100.0
		]
	]
],
[
	"match_phrase" => [
		"body" => [
			"query" => $q,
			"analyzer" => 'search_analyzer',
			"slop" => "1",
			"boost" => 45.0
		]
	]
],
[
	"match" => [
		"body" => [
			"query" => $q,
			"analyzer" => 'search_analyzer',
			"operator" => "and",
			"boost" => 10.0
		]
	]
],
[
	"match" => [
		"body" => [
			"query" => $q,
			"analyzer" => 'search_analyzer',
			"operator" => "or",
			"fuzziness" => "1",
			"boost" => 1.0
		]
	]
]

```

When I search _I'm a student_ the result is:  
1- I am a student.  
2- I'm a student.  
3- there are students.  
4- am i a student?

While I expected the result in order:  
1- I'm a student.  
2- I am a student.  
3- am i a student?  
4- there are students.

Please help me to understand this type of search with contraction words to get better relevance. Thanks in advance.

---

<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:** [September 20, 2018, 12:54pm UTC](https://discuss.elastic.co/t/how-to-search-a-contraction-word/145731/2 "2018-09-20T12:54:27Z")

</div>

Closed on September 20, 2018, 12:54pm UTC

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