Hi Dan, really helpful thanks. I was struggling a bit with the java API. This got me going again. Olly
On Friday, April 11, 2014 6:11:41 AM UTC+1, Dan Tuffery wrote: > > I did a quick test, this works: > > *Create mapping* > > curl -XPUT 'http://localhost:9200/example/test/_mapping' -d > '{ > "test": { > "properties": { > "my_suggest": { > "type": "completion" > } > } > } > }' > > *Index value* > > curl -XPUT 'http://localhost:9200/example/test/1/' -d > '{ > "my_suggest": "FooFighters" > }' > > *Java API code* > > CompletionSuggestionBuilder compBuilder = new > CompletionSuggestionBuilder("my_suggest"); > compBuilder.text("Foo"); > compBuilder.field("my_suggest"); > > SuggestRequestBuilder suggestRequestBuilder = client > .prepareSuggest("example").addSuggestion(compBuilder); > > SuggestResponse suggestResponse = > suggestRequestBuilder.execute().actionGet(); > CompletionSuggestion compSuggestion = > suggestResponse.getSuggest().getSuggestion("my_suggest"); > > List<CompletionSuggestion.Entry> entryList = compSuggestion.getEntries(); > if (entryList != null) { > CompletionSuggestion.Entry entry = entryList.get(0); > List<CompletionSuggestion.Entry.Option> options = entry.getOptions(); > if (options != null) { > CompletionSuggestion.Entry.Option option = options.get(0); > //the value of toReturn is 'FooFighters' > String toReturn = option.getText().string() > } > > Dan > > > On Thursday, April 10, 2014 2:50:05 PM UTC+1, Bill Wortinger wrote: >> >> Hello Dan, thanks again for all the help but I can't seem to get anything >> to return. Here is my full code, there has to be something I'm missing. >> Maybe in the indexing, the mapping? >> >> Mapping: >> putMappingResponse = new PutMappingRequestBuilder(newClient >> .admin().indices()) >> .setIndices(INDEX_NAME) >> .setType(INDEX_TYPE) >> .setSource(jsonBuilder().startObject("suggest") >> .field("type", "completion") >> .endObject().execute().actionGet()); >> >> Method: >> public String searchSuggestions(String suggestion) { >> // Creates suggestions based on Document Titles. >> String toReturn = ""; >> >> Client localClient = getElasticSearchClient(); >> >> CompletionSuggestionBuilder compBuilder = new >> CompletionSuggestionBuilder("completion"); >> compBuilder.text(suggestion); >> compBuilder.field("suggest"); >> >> SuggestRequestBuilder suggestRequestBuilder = localClient >> .prepareSuggest(INDEX_NAME).addSuggestion(compBuilder); >> >> SuggestResponse suggestResponse = >> suggestRequestBuilder.execute().actionGet(); >> CompletionSuggestion compSuggestion = >> suggestResponse.getSuggest().getSuggestion("completion"); >> >> List<CompletionSuggestion.Entry> entryList = compSuggestion.getEntries(); >> if (entryList != null) { >> CompletionSuggestion.Entry entry = entryList.get(0); >> List<CompletionSuggestion.Entry.Option> options = entry.getOptions(); >> if (options != null) { >> CompletionSuggestion.Entry.Option option = options.get(0); >> toReturn = option.getText().string(); >> } >> } >> return toReturn; >> } >> >> Index: >> response = localClient.prepareIndex(INDEX_NAME, INDEX_TYPE) >> >> .setSource(jsonBuilder().startObject("suggest").field("input","FooFighters").endObject()).execute().actionGet(); >> >> Thanks for all the help, I'm basically shooting in the dark hoping >> somebody with more experience can spot the issue. >> >> >> >> >> >> On Wed, Apr 9, 2014 at 3:56 AM, Dan Tuffery <[email protected]> wrote: >> >>> This looks wrong, >>> >>> *Suggest.Suggestion.Entry.Option option2 = >>> suggestResponse.getSuggest().getSuggestion("completion").getEntries().get(0).getOptions().get(0);* >>> >>> it should be: >>> >>> *Suggest.Suggestion.Entry.Option option2 = * >>> *suggestResponse.getSuggest().getSuggestion("suggest").getEntries().get(0).getOptions().get(0);* >>> >>> Where *getSuggestion* is getting the field name you supplied in the >>> request. >>> >>> Dan >>> >>> >>> So it looks like your query is returning zero results. Can you see >>> values indexed for the field 'at' >>> >>> >>> On Tuesday, April 8, 2014 4:07:57 PM UTC+1, Bill Wortinger wrote: >>> >>>> Great resource! Thank you, >>>> >>>> >>>> >>>> >>>> >>>> >>>> >>>> >>>> *CompletionSuggestionBuilder compBuilder = new >>>> CompletionSuggestionBuilder("completion"); >>>> compBuilder.text(suggestion); compBuilder.field("suggest"); >>>> SuggestRequestBuilder suggestRequestBuilder = >>>> localClient.prepareSuggest(INDEX_NAME) >>>> .addSuggestion(compBuilder); SuggestResponse >>>> suggestResponse >>>> = suggestRequestBuilder.execute().actionGet();* >>>> >>>> When executing >>>> >>>> >>>> *Suggest.Suggestion.Entry.Option option2 = >>>> suggestResponse.getSuggest().getSuggestion("completion").getEntries().get(0).getOptions().get(0);* >>>> A null is returned. >>>> >>>> Below is my index. >>>> >>>> *.startObject("suggest").field("type", "completion").endObject()* >>>> >>>> Thanks again! >>>> >>>> >>>> >>>> >>>> >>>> >>>> On Tue, Apr 8, 2014 at 9:14 AM, Dan <[email protected]> wrote: >>>> >>>>> What is the issue you're seeing? Have a look at the examples in the >>>>> tests: >>>>> >>>>> https://github.com/elasticsearch/elasticsearch/ >>>>> blob/master/src/test/java/org/elasticsearch/search/suggest/ >>>>> CompletionSuggestSearchTests.java >>>>> >>>>> Dan >>>>> >>>>> >>>>> On Tuesday, April 8, 2014 1:43:29 PM UTC+1, Bill Wortinger wrote: >>>>>> >>>>>> Thanks for the heads up Alex, I'll remove the .setTypes(). >>>>>> >>>>>> Dan, this is what I have so far; >>>>>> >>>>>> CompletionSuggestionBuilder compBuilder = new >>>>>> CompletionSuggestionBuilder("complete"); >>>>>> compBuilder.text('n"); >>>>>> compBuilder.field("suggest"); >>>>>> SuggestRequestBuilder suggestRequestBuilder = >>>>>> client.prepareSuggest(INDEX_NAME); >>>>>> suggestRequestBuilder.addSuggestion(compBuilder); >>>>>> SuggestResponse suggestResponse = suggestRequestBuilder.execute( >>>>>> ).actionGet(); >>>>>> >>>>>> CompletionSuggestion compSuggestion = suggestResponse.getSuggest().g >>>>>> etSuggestion("complete"); >>>>>> >>>>>> List<CompletionSuggestion.Entry> entryList = >>>>>> compSuggestion.getEntries(); >>>>>> if(entryList != null) { >>>>>> CompletionSuggestion.Entry entry = entryList.get(0); >>>>>> List<CompletionSuggestion.Entry.Option> options >>>>>> =entry.getOptions(); >>>>>> if(options != null) { >>>>>> CompletionSuggestion.Entry.Option option = >>>>>> options.get(0); >>>>>> toReturn = option.getText().string(); >>>>>> } >>>>>> } >>>>>> return toReturn; >>>>>> >>>>>> I've made progress! But now it's falling apart when I try parsing the >>>>>> entries from the suggestReponse. So, am I doing this correctly? Missing >>>>>> something? >>>>>> >>>>>> Thanks! >>>>>> >>>>>>> >>>>>>> >>>>>> On Monday, April 7, 2014 6:26:37 AM UTC-4, Dan wrote: >>>>>>> >>>>>>> Use the SuggestRequestBuilder, i.e. >>>>>>> >>>>>>> CompletionSuggestionBuilder compBuilder = new >>>>>>> CompletionSuggestionBuilder("complete"); >>>>>>> compBuilder.text("n"); >>>>>>> compBuilder.field("suggest"); >>>>>>> >>>>>>> SuggestRequestBuilder suggestRequestBuilder = >>>>>>> client.prepareSuggest(INDEX_NAME); >>>>>>> suggestRequestBuilder.addSuggestion(compBuilder); >>>>>>> SuggestResponse suggestResponse = suggestRequestBuilder.execute( >>>>>>> ).actionGet(); >>>>>>> >>>>>>> Dan >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> On Mon, Apr 7, 2014 at 8:49 AM, Alexander Reelsen <[email protected] >>>>>>> > wrote: >>>>>>> >>>>>>>> Hey, >>>>>>>> >>>>>>>> looks ok. Minor note: Types are simply ignored for suggestions. >>>>>>>> What are you getting back? Nothing? >>>>>>>> Can you create a fully working gist, including creation of the >>>>>>>> mapping and indexing? Then debugging and finding your possible cause >>>>>>>> would >>>>>>>> be a lot easier. >>>>>>>> >>>>>>>> >>>>>>>> --Alex >>>>>>>> >>>>>>>> >>>>>>>> On Fri, Apr 4, 2014 at 4:02 PM, Bill Wortinger >>>>>>>> <[email protected]>wrote: >>>>>>>> >>>>>>>>> I have my indices created, and mapping type for my 'suggest' field >>>>>>>>> set to completion. I can't figure out how to configure the query for >>>>>>>>> completion suggestions in elastic-search (Java API). >>>>>>>>> >>>>>>>>> I'm trying to use this Query to base my implementation off of. >>>>>>>>> "song-suggest" : { "text" : "n", "completion" : { "field" : "suggest" >>>>>>>>> } } Here's >>>>>>>>> what I have so far, >>>>>>>>> >>>>>>>>> CompletionSuggestionBuilder compBuilder = new >>>>>>>>> CompletionSuggestionBuilder("complete"); >>>>>>>>> compBuilder.text("n.."); >>>>>>>>> compBuilder.field("suggest"); >>>>>>>>> >>>>>>>>> SearchResponse searchResponse = >>>>>>>>> localClient.prepareSearch(INDEX_NAME) >>>>>>>>> .setTypes("completion") >>>>>>>>> .setQuery(QueryBuilders.matchAllQuery()) >>>>>>>>> .addSuggestion(compBuilder) >>>>>>>>> .execute().actionGet(); >>>>>>>>> >>>>>>>>> CompletionSuggestion compSuggestion = >>>>>>>>> searchResponse.getSuggest().getSuggestion("complete"); >>>>>>>>> >>>>>>>>> Am I missing something, doing something wrong? Thanks! >>>>>>>>> >>>>>>>>> -- >>>>>>>>> You received this message because you are subscribed to the Google >>>>>>>>> Groups "elasticsearch" group. >>>>>>>>> To unsubscribe from this group and stop receiving emails from it, >>>>>>>>> send an email to [email protected]. >>>>>>>>> To view this discussion on the web visit >>>>>>>>> https://groups.google.com/d/msgid/elasticsearch/06792c37-646 >>>>>>>>> c-4b59-bdb3-f23cc51bd134%40googlegroups.com<https://groups.google.com/d/msgid/elasticsearch/06792c37-646c-4b59-bdb3-f23cc51bd134%40googlegroups.com?utm_medium=email&utm_source=footer> >>>>>>>>> . >>>>>>>>> For more options, visit https://groups.google.com/d/optout. >>>>>>>>> >>>>>>>> >>>>>>>> -- >>>>>>>> You received this message because you are subscribed to the Google >>>>>>>> Groups "elasticsearch" group. >>>>>>>> To unsubscribe from this group and stop receiving emails from it, >>>>>>>> send an email to [email protected]. >>>>>>>> To view this discussion on the web visit >>>>>>>> https://groups.google.com/d/msgid/elasticsearch/CAGCwEM9D76G >>>>>>>> mrXqdnBy%3DkstCN4NDtfkS3X%3DyXd0uMdTVpSUBvg%40mail.gmail.com<https://groups.google.com/d/msgid/elasticsearch/CAGCwEM9D76GmrXqdnBy%3DkstCN4NDtfkS3X%3DyXd0uMdTVpSUBvg%40mail.gmail.com?utm_medium=email&utm_source=footer> >>>>>>>> . >>>>>>>> >>>>>>>> For more options, visit https://groups.google.com/d/optout. >>>>>>>> >>>>>>> >>>>>>> -- >>>>> You received this message because you are subscribed to a topic in the >>>>> Google Groups "elasticsearch" group. >>>>> To unsubscribe from this topic, visit https://groups.google.com/d/ >>>>> topic/elasticsearch/06nbxJnYfDo/unsubscribe. >>>>> To unsubscribe from this group and all its topics, send an email to >>>>> [email protected]. >>>>> To view this discussion on the web visit https://groups.google.com/d/ >>>>> msgid/elasticsearch/f6e28fc8-cef5-4f13-8dce-04e0bcfc5404% >>>>> 40googlegroups.com<https://groups.google.com/d/msgid/elasticsearch/f6e28fc8-cef5-4f13-8dce-04e0bcfc5404%40googlegroups.com?utm_medium=email&utm_source=footer> >>>>> . >>>>> >>>>> For more options, visit https://groups.google.com/d/optout. >>>>> >>>> >>>> -- >>> You received this message because you are subscribed to a topic in the >>> Google Groups "elasticsearch" group. >>> To unsubscribe from this topic, visit >>> https://groups.google.com/d/topic/elasticsearch/06nbxJnYfDo/unsubscribe. >>> To unsubscribe from this group and all its topics, send an email to >>> [email protected]. >>> To view this discussion on the web visit >>> https://groups.google.com/d/msgid/elasticsearch/6fa70b40-0fb7-4735-851d-bf8bc872fd38%40googlegroups.com<https://groups.google.com/d/msgid/elasticsearch/6fa70b40-0fb7-4735-851d-bf8bc872fd38%40googlegroups.com?utm_medium=email&utm_source=footer> >>> . >>> >>> For more options, visit https://groups.google.com/d/optout. >>> >> >> -- You received this message because you are subscribed to the Google Groups "elasticsearch" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/e1675de0-6c43-4a8e-b2d3-e73f41d8bebf%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
