Elastic Search Partial Search

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.

$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

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

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

$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

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

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

"query"=>[
    "query_string" =>[
        "query" => "doct*"
    ]
]
"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

You may want to look at chapters 16.x Of the Definitive Guide including index-time optimisation chapters to ensure adequate query performance.

Hey thanks
I am looking this now.
Thanks

From the same page ...

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.

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