Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Add support for ES 0.9 Suggest Api #378

Closed
damienalexandre opened this issue Apr 29, 2013 · 12 comments
Closed

[Feature] Add support for ES 0.9 Suggest Api #378

damienalexandre opened this issue Apr 29, 2013 · 12 comments

Comments

@damienalexandre
Copy link
Contributor

ElasticSearch 0.9 provide a new API for search suggestion.

We can already use it with Elastica but it's not clean IMO:

$elasticaQuery      = new Elastica\Query();
$elasticaQuery->setParam('suggest', array(
  "text" => "Mickal Jockson",
  "my-suggest" => array(
    "term" => array(
      "field" => "_all"
    )
  )
));

The suggestions must be fetched from the Response:

$datas = $resultSet->getResponse()->getData();
var_dump($datas['suggest']);

We need (this is only a proposal):

  • a new Suggests Search object, holding:
    • a TermSuggest object (or Suggest?) and a PhraseSuggestwith:
      • setText
      • setField (mandatory)
      • a way to set all the other options
  • a method Query::setSuggest (like for the Facets)
  • a way to hit directly the new _suggest API endpoint
  • a method ResultSet::getSuggest (like for the Facets)
@ruflin
Copy link
Owner

ruflin commented Apr 30, 2013

Very interesting. I didn't see this feature so far. So the question is, how we should treat "suggest". Should we handle it the same way as Query, Filter and Facets?

If I look at the documentation, it seems like a lot is still coming here (not only Term and Phrase).

What do you think?

@damienalexandre
Copy link
Contributor Author

From my point of view, it's a lot like the Facet mechanism:

  • multiple type of Suggest object are already known: Term & Phrase
  • you add them on a Query like with setFacets (the only diff is that we must keep the array keys, in my example "my-suggest" is required)
  • you get the result from the ResultSet

The only difference is that there is a dedicated API end-point that Elastica should also expose.

@ruflin
Copy link
Owner

ruflin commented May 1, 2013

I'm not sure if it is necessary to support the _suggest API endpoint directly. I assume that the following two requests are the same:

curl -s -XPOST 'localhost:9200/_search' -d '{
  "suggest" : {
    "my-title-suggestions-1" : {
      "text" : "devloping distibutd saerch engies",
      "term" : {
        "size" : 3,
        "field" : "title"  
      }
    }
  }
}'


curl -s -XPOST 'localhost:9200/_suggest' -d '{
    "my-title-suggestions-1" : {
      "text" : "devloping distibutd saerch engies",
      "term" : {
        "size" : 3,
        "field" : "title"  
      }
  }
}'

Or is there a specific reason you think the endpoint needs to be supported (except for shorter notation)?

@damienalexandre
Copy link
Contributor Author

We should have a Request Type at least, or a way to hit only the suggestions for a given Search. You are right, your two examples are the sames but the first one return all the documents too, it's like a match all query.

The main advantage of the _suggest end point is to allow faster & lighter suggestion only searches (for async suggestion i.e.) - and I think that if Elastica support Suggestion, there must be a way to hit the _suggest only path.

@ruflin
Copy link
Owner

ruflin commented May 2, 2013

Ok, so what you say is, that the two examples actually do not return the same result. I wasn't aware of that (and should test it ...). So this is different from filters or facets where we don't have this as far as I know.

So I agree (in case it is different), that we should offer this capability in Elastica. As Elastica always makes it possible to build your queries yourself, this is already now possible. But there should be a nicer way to do it.

Not sure yet, where we should place this _suggest.

@lonamiaec
Copy link

Hi, what happended with this feature? Is there any plan to add it?

@ruflin
Copy link
Owner

ruflin commented Sep 9, 2013

@damienalexandre Any updates here?

@damienalexandre
Copy link
Contributor Author

We need to decide how to implement this, then the PR will be pretty easy to do.

So, here is what we need:

  • the _suggest endpoint should be accessible, from root, from an indices and from a type
    • this call return a ResultSet
  • the suggest query option must be added to add a suggestion node
  • we need the appropriate getter to get the suggestions from the results
  • the suggestion text can be global or local to each suggestion
  • there is two type of suggestion: simple_phrase and term, and an experimental one: completion
  • new Suggest objects needs to be created:
    • Elastica\Suggest\AbstractSuggest
    • Elastica\Suggest\TermSuggest
    • Elastica\Suggest\SimplePhraseSuggest

Let's try to imagine the API:

// Simple
$search = new Search($this->getClient());
$search->addIndex($index);
$search->addSuggest(
  new TermSuggest("a-name", array("text" => "toto", "term" => array("field" => "body"))
);

This example lack for the support of global text (we should be able to set multiple Suggest to the search and only set one "text", is that code a good idea?

$search->setSuggestText("toto");

Getting back the results should be as easy as this:

$results = $search->search();
$results->getSuggests(); // array('a-name' => ...)

I do not have much time to explore the other needs but feel free to complete 😗

@lonamiaec
Copy link

@damienalexandre I like your approach.

  • Access the _suggest endpoint its a must if we only want suggestions, not hits.
  • I would forget completion type by now, because it can change until it's finished.
  • I think the ResultSet modification its the easiest part, because suggest is present in init function, but we dont save it anywhere.
  • Global text it's very usefull, and your idea is clear.

Your imaginary API is powerfull and simple enough for me :) @ruflin what do you think about it?

@ruflin
Copy link
Owner

ruflin commented Sep 17, 2013

As a reminder for myself: #460

@ruflin
Copy link
Owner

ruflin commented Sep 17, 2013

The main thing I would change is to call it:

Elastica\Suggest\Term
Elastica\Suggest\SimplePhrase

Same naming convention as for query and filter.

Why is it necessary to set the "simple" suggest with text? Is that necessary (yet)?

@damienalexandre damienalexandre mentioned this issue Sep 21, 2013
3 tasks
@ruflin
Copy link
Owner

ruflin commented Feb 8, 2014

Close as pull requests were merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants