# Elastic Search Partial Search

**URL:** <https://discuss.elastic.co/t/elastic-search-partial-search/155318>\
**Category:** Elasticsearch\
**Created:** [November 5, 2018, 12:58am UTC](https://discuss.elastic.co/t/elastic-search-partial-search/155318 "2018-11-05T00:58:22Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nush](https://avatars.discourse-cdn.com/v4/letter/n/d26b3c/32.png) [@Nush](https://discuss.elastic.co/u/Nush)\
**Post date:** [November 5, 2018, 12:58am UTC](https://discuss.elastic.co/t/elastic-search-partial-search/155318/1 "2018-11-05T00:58:22Z")

</div>

Hey,  
I am trying to create a partial search with elasticsearch but it's not working then I expected. But full word its work fine.

```auto
$esQuery = [
	'index'	=> $category,
	'type'	=> $category,
	'body'	=> [
	    "from"	=> ($page - 1) * $countPerPage,
	     "size"	=> $countPerPage,
	     'highlight'	=> [
			'fields' => [
			'*' => [
				'pre_tags' => ['<mark>'],
			        'post_tags' => ['</mark>'],
				]
			]
		],
		"query" => [
			"multi_match" => [
				"query"	=> $query
					  ]
				] ]
			]
	    ];
```

I am using PHP for creating this code  
For example, if I am using "Doctor" its work well but if someone tries to "Doc" It does not give you anything,  
{Data will be coming from Salesforce}  
Please help me to find a proper solution for this matter  
Thanks

---

<div class="post-metadata">

**Author:** ![Jaspreet\_Singh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jaspreet_singh/32/58296_2.png) [@Jaspreet\_Singh](https://discuss.elastic.co/u/Jaspreet_Singh)\
**Post date:** [November 5, 2018, 1:45am UTC](https://discuss.elastic.co/t/elastic-search-partial-search/155318/2 "2018-11-05T01:45:23Z")

</div>

You should try out `match_phrase_prefix` query instead of multi\_match. Check this - [https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query-phrase-prefix.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query-phrase-prefix.html)

---

<div class="post-metadata">

**Author:** ![Nush](https://avatars.discourse-cdn.com/v4/letter/n/d26b3c/32.png) [@Nush](https://discuss.elastic.co/u/Nush)\
**Post date:** [November 5, 2018, 2:11am UTC](https://discuss.elastic.co/t/elastic-search-partial-search/155318/3 "2018-11-05T02:11:28Z")

</div>

Hey  
Thanks for this reply. I try this option. But still didn't get any reply.

```auto
$esQuery = [
  'index'	=> $category,
  'type'	=> $category,
  'body'	=> [
    "from"	=> ($page - 1) * $countPerPage,
    "size"	=> $countPerPage,
    'highlight'	=> [
      'fields' => [
        '*' => [
          'pre_tags' => ['<mark>'],
          'post_tags' => ['</mark>'],
        ]
      ]
    ],
    "query"=>[
        "match_phrase_prefix" =>[
            "message" =>[
              "query" => "doct"
            ]
        ]
    ]
  ]
];
```

This is the reply from search

```auto
Array
(
    [took] => 2
    [timed_out] => 
    [_shards] => Array
        (
            [total] => 5
            [successful] => 5
            [skipped] => 0
            [failed] => 0
        )

    [hits] => Array
        (
            [total] => 0
            [max_score] => 
            [hits] => Array
                (
                )

        )

)
```

Thanks again

---

<div class="post-metadata">

**Author:** ![gabriel\_tessier](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gabriel_tessier/32/27911_2.png) [@gabriel\_tessier](https://discuss.elastic.co/u/gabriel_tessier)\
**Post date:** [November 5, 2018, 2:39am UTC](https://discuss.elastic.co/t/elastic-search-partial-search/155318/4 "2018-11-05T02:39:33Z")

</div>

Can I suggest this: [https://www.elastic.co/guide/en/elasticsearch/reference/6.4/query-dsl-query-string-query.html](https://www.elastic.co/guide/en/elasticsearch/reference/6.4/query-dsl-query-string-query.html)

```
"query"=>[
    "query_string" =>[
        "query" => "doct*"
    ]
]
```

---

<div class="post-metadata">

**Author:** ![Nush](https://avatars.discourse-cdn.com/v4/letter/n/d26b3c/32.png) [@Nush](https://discuss.elastic.co/u/Nush)\
**Post date:** [November 5, 2018, 2:49am UTC](https://discuss.elastic.co/t/elastic-search-partial-search/155318/5 "2018-11-05T02:49:06Z")

</div>

> [@gabriel\_tessier](#):
>
> query\_string

```auto
"query" => [
    "bool" => [
        "must" => [
            "match"=> ["text" => "doctor"] 
        ]
    ]
]
$esQuery = [
  'index'	=> $category,
  'type'	=> $category,
  'body'	=> [
    "from"	=> ($page - 1) * $countPerPage,
    "size"	=> $countPerPage,
    'highlight'	=> [
      'fields' => [
        '*' => [
          'pre_tags' => ['<mark>'],
          'post_tags' => ['</mark>'],
        ]
      ]
    ],
    "query"=>[
        "query_string" =>[
              "query" => $query
        ]
    ]
  ]
];
```

Thanks a lot, this is working fine and I got good result sets,  
Thanks again

---

<div class="post-metadata">

**Author:** ![michaelh](https://avatars.discourse-cdn.com/v4/letter/m/53a042/32.png) [@michaelh](https://discuss.elastic.co/u/michaelh)\
**Post date:** [November 5, 2018, 2:53am UTC](https://discuss.elastic.co/t/elastic-search-partial-search/155318/6 "2018-11-05T02:53:41Z")

</div>

You may want to look at chapters 16.x Of the [Definitive Guide](https://www.elastic.co/guide/en/elasticsearch/guide/current/partial-matching.html) including index-time optimisation chapters to ensure adequate query performance.

---

<div class="post-metadata">

**Author:** ![Nush](https://avatars.discourse-cdn.com/v4/letter/n/d26b3c/32.png) [@Nush](https://discuss.elastic.co/u/Nush)\
**Post date:** [November 5, 2018, 2:54am UTC](https://discuss.elastic.co/t/elastic-search-partial-search/155318/7 "2018-11-05T02:54:27Z")

</div>

Hey thanks  
I am looking this now.  
Thanks

---

<div class="post-metadata">

**Author:** ![Jaspreet\_Singh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jaspreet_singh/32/58296_2.png) [@Jaspreet\_Singh](https://discuss.elastic.co/u/Jaspreet_Singh)\
**Post date:** [November 5, 2018, 9:39pm UTC](https://discuss.elastic.co/t/elastic-search-partial-search/155318/8 "2018-11-05T21:39:36Z")

</div>

From the same page ...

```auto
Be aware that wildcard queries can use an enormous amount of memory and perform very badly 

```

I would be very careful in using wildcards query.  
You should take another look at match phrase prefix (btw it worked for me when I specified incomplete word). The advantae with match phrase prefix is that you can configure how many expansions you want, hence the performance can be easily controlled.

---

<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:** [December 3, 2018, 9:39pm UTC](https://discuss.elastic.co/t/elastic-search-partial-search/155318/9 "2018-12-03T21:39:40Z")

</div>

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