Skip to content

CONSOLEify term and phrase suggester docs #19577

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

Merged
merged 1 commit into from
Jul 26, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ buildRestTests.docs = fileTree(projectDir) {

Closure setupTwitter = { String name, int count ->
buildRestTests.setups[name] = '''
- do:
indices.create:
index: twitter
body:
settings:
number_of_shards: 1
number_of_replicas: 1
- do:
bulk:
index: twitter
Expand Down
10 changes: 5 additions & 5 deletions docs/reference/indices/flush.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -153,18 +153,18 @@ sync-flushed:
--------------------------------------------------
{
"_shards": {
"total": 10,
"successful": 10,
"total": 2,
"successful": 2,
"failed": 0
},
"twitter": {
"total": 10,
"successful": 10,
"total": 2,
"successful": 2,
"failed": 0
}
}
--------------------------------------------------
// TESTRESPONSE[s/"successful": 10/"successful": 5/]
// TESTRESPONSE[s/"successful": 2/"successful": 1/]

Here is what it looks like when one shard group failed due to pending operations:

Expand Down
237 changes: 56 additions & 181 deletions docs/reference/search/suggesters.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,44 @@ The suggest request part is either defined alongside the query part in a

[source,js]
--------------------------------------------------
curl -s -XPOST 'localhost:9200/_search' -d '{
POST twitter/_search
{
"query" : {
...
"match": {
"message": "tring out Elasticsearch"
}
},
"suggest" : {
...
"my-suggestion" : {
"text" : "trying out Elasticsearch",
"term" : {
"field" : "message"
}
}
}
}'
}
--------------------------------------------------
// CONSOLE
// TEST[setup:twitter]

Suggest requests executed against the `_suggest` endpoint should omit
the surrounding `suggest` element which is only used if the suggest
request is part of a search.

[source,js]
--------------------------------------------------
curl -XPOST 'localhost:9200/_suggest' -d '{
POST _suggest
{
"my-suggestion" : {
"text" : "the amsterdma meetpu",
"text" : "tring out Elasticsearch",
"term" : {
"field" : "body"
"field" : "message"
}
}
}'
}
--------------------------------------------------
// CONSOLE
// TEST[setup:twitter]

Several suggestions can be specified per request. Each suggestion is
identified with an arbitrary name. In the example below two suggestions
Expand All @@ -43,21 +56,24 @@ the `term` suggester, but have a different `text`.

[source,js]
--------------------------------------------------
"suggest" : {
POST _suggest
{
"my-suggest-1" : {
"text" : "the amsterdma meetpu",
"text" : "tring out Elasticsearch",
"term" : {
"field" : "body"
"field" : "message"
}
},
"my-suggest-2" : {
"text" : "the rottredam meetpu",
"text" : "kmichy",
"term" : {
"field" : "title"
"field" : "user"
}
}
}
--------------------------------------------------
// CONSOLE
// TEST[setup:twitter]

The below suggest response example includes the suggestion response for
`my-suggest-1` and `my-suggest-2`. Each suggestion part contains
Expand All @@ -68,44 +84,35 @@ in the suggest text and if found an arbitrary number of options.
[source,js]
--------------------------------------------------
{
...
"suggest": {
"my-suggest-1": [
{
"text" : "amsterdma",
"offset": 4,
"length": 9,
"options": [
...
]
},
...
],
"my-suggest-2" : [
...
]
}
...
"_shards": ...
"my-suggest-1": [ {
"text": "tring",
"offset": 0,
"length": 5,
"options": [ {"text": "trying", "score": 0.8, "freq": 1 } ]
}, {
"text": "out",
"offset": 6,
"length": 3,
"options": []
}, {
"text": "elasticsearch",
"offset": 10,
"length": 13,
"options": []
} ],
"my-suggest-2": ...
}
--------------------------------------------------
// TESTRESPONSE[s/"_shards": \.\.\./"_shards": "$body._shards",/]
// TESTRESPONSE[s/"my-suggest-2": \.\.\./"my-suggest-2": "$body.my-suggest-2"/]


Each options array contains an option object that includes the
suggested text, its document frequency and score compared to the suggest
entry text. The meaning of the score depends on the used suggester. The
term suggester's score is based on the edit distance.

[source,js]
--------------------------------------------------
"options": [
{
"text": "amsterdam",
"freq": 77,
"score": 0.8888889
},
...
]
--------------------------------------------------

[float]
[[global-suggest]]
=== Global suggest text
Expand All @@ -116,163 +123,31 @@ and applies to the `my-suggest-1` and `my-suggest-2` suggestions.

[source,js]
--------------------------------------------------
"suggest" : {
"text" : "the amsterdma meetpu",
POST _suggest
{
"text" : "tring out Elasticsearch",
"my-suggest-1" : {
"term" : {
"field" : "title"
"field" : "message"
}
},
"my-suggest-2" : {
"term" : {
"field" : "body"
"field" : "user"
}
}
}
--------------------------------------------------
// CONSOLE
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed this example because it didn't seem to buy much after the first example.


The suggest text can in the above example also be specified as
suggestion specific option. The suggest text specified on suggestion
level override the suggest text on the global level.

[float]
=== Other suggest example

In the below example we request suggestions for the following suggest
text: `devloping distibutd saerch engies` on the `title` field with a
maximum of 3 suggestions per term inside the suggest text. Note that in
this example we set `size` to `0`. This isn't required, but a
nice optimization. The suggestions are gathered in the `query` phase and
in the case that we only care about suggestions (so no hits) we don't
need to execute the `fetch` phase.

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

The above request could yield the response as stated in the code example
below. As you can see if we take the first suggested options of each
suggestion entry we get `developing distributed search engines` as
result.

[source,js]
--------------------------------------------------
{
...
"suggest": {
"my-title-suggestions-1": [
{
"text": "devloping",
"offset": 0,
"length": 9,
"options": [
{
"text": "developing",
"freq": 77,
"score": 0.8888889
},
{
"text": "deloping",
"freq": 1,
"score": 0.875
},
{
"text": "deploying",
"freq": 2,
"score": 0.7777778
}
]
},
{
"text": "distibutd",
"offset": 10,
"length": 9,
"options": [
{
"text": "distributed",
"freq": 217,
"score": 0.7777778
},
{
"text": "disributed",
"freq": 1,
"score": 0.7777778
},
{
"text": "distribute",
"freq": 1,
"score": 0.7777778
}
]
},
{
"text": "saerch",
"offset": 20,
"length": 6,
"options": [
{
"text": "search",
"freq": 1038,
"score": 0.8333333
},
{
"text": "smerch",
"freq": 3,
"score": 0.8333333
},
{
"text": "serch",
"freq": 2,
"score": 0.8
}
]
},
{
"text": "engies",
"offset": 27,
"length": 6,
"options": [
{
"text": "engines",
"freq": 568,
"score": 0.8333333
},
{
"text": "engles",
"freq": 3,
"score": 0.8333333
},
{
"text": "eggies",
"freq": 1,
"score": 0.8333333
}
]
}
]
}
...
}
--------------------------------------------------

include::suggesters/term-suggest.asciidoc[]

include::suggesters/phrase-suggest.asciidoc[]

include::suggesters/completion-suggest.asciidoc[]

include::suggesters/context-suggest.asciidoc[]


Loading