2e68207d6d
# Suggest feature The suggest feature suggests similar looking terms based on a provided text by using a suggester. At the moment there the only supported suggester is `fuzzy`. The suggest feature is available from version `0.21.0`. # Fuzzy suggester The `fuzzy` suggester suggests terms based on edit distance. The provided suggest text is analyzed before terms are suggested. The suggested terms are provided per analyzed suggest text token. The `fuzzy` suggester doesn't take the query into account that is part of request. # Suggest API The suggest request part is defined along side the query part as top field in the json request. ``` curl -s -XPOST 'localhost:9200/_search' -d '{ "query" : { ... }, "suggest" : { ... } }' ``` Several suggestions can be specified per request. Each suggestion is identified with an arbitary name. In the example below two suggestions are requested. Both `my-suggest-1` and `my-suggest-2` suggestions use the `fuzzy` suggester, but have a different `text`. ``` "suggest" : { "my-suggest-1" : { "text" : "the amsterdma meetpu", "fuzzy" : { "field" : "body" } }, "my-suggest-2" : { "text" : "the rottredam meetpu", "fuzzy" : { "field" : "title", } } } ``` The below suggest response example includes the suggestion response for `my-suggest-1` and `my-suggest-2`. Each suggestion part contains entries. Each entry is effectively a token from the suggest text and contains the suggestion entry text, the original start offset and length in the suggest text and if found an arbitary number of options. ``` { ... "suggest": { "my-suggest-1": [ { "text" : "amsterdma", "offset": 4, "length": 9, "options": [ ... ] }, ... ], "my-suggest-2" : [ ... ] } ... } ``` Each options array contains a 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 fuzzy suggester's score is based on the edit distance. ``` "options": [ { "text": "amsterdam", "freq": 77, "score": 0.8888889 }, ... ] ``` # Global suggest text To avoid repitition of the suggest text, it is possible to define a global text. In the example below the suggest text is defined globally and applies to the `my-suggest-1` and `my-suggest-2` suggestions. ``` "suggest" : { "text" : "the amsterdma meetpu" "my-suggest-1" : { "fuzzy" : { "field" : "title" } }, "my-suggest-2" : { "fuzzy" : { "field" : "body" } } } ``` The suggest text can in the above example also be specied as suggestion specific option. The suggest text specified on suggestion level override the suggest text on the global level. # 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 use the `count` search type. This isn't required, but a nice optimalization. The suggestions are gather 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. ``` curl -s -XPOST 'localhost:9200/_search?search_type=count' -d '{ "suggest" : { "my-title-suggestions-1" : { "text" : "devloping distibutd saerch engies", "fuzzy" : { "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. ``` { ... "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 } ] } ] } ... } ``` # Common suggest options: * `text` - The suggest text. The suggest text is a required option that needs to be set globally or per suggestion. # Common fuzzy suggest options * `field` - The field to fetch the candidate suggestions from. This is an required option that either needs to be set globally or per suggestion. * `analyzer` - The analyzer to analyse the suggest text with. Defaults to the search analyzer of the suggest field. * `size` - The maximum corrections to be returned per suggest text token. * `sort` - Defines how suggestions should be sorted per suggest text term. Two possible value: ** `score` - Sort by sore first, then document frequency and then the term itself. ** `frequency` - Sort by document frequency first, then simlarity score and then the term itself. * `suggest_mode` - The suggest mode controls what suggestions are included or controls for what suggest text terms, suggestions should be suggested. Three possible values can be specified: ** `missing` - Only suggest terms in the suggest text that aren't in the index. This is the default. ** `popular` - Only suggest suggestions that occur in more docs then the original suggest text term. ** `always` - Suggest any matching suggestions based on terms in the suggest text. # Other fuzzy suggest options: * `lowercase_terms` - Lower cases the suggest text terms after text analyzation. * `max_edits` - The maximum edit distance candidate suggestions can have in order to be considered as a suggestion. Can only be a value between 1 and 2. Any other value result in an bad request error being thrown. Defaults to 2. * `min_prefix` - The number of minimal prefix characters that must match in order be a candidate suggestions. Defaults to 1. Increasing this number improves spellcheck performance. Usually misspellings don't occur in the beginning of terms. * `min_query_length` - The minimum length a suggest text term must have in order to be included. Defaults to 4. * `shard_size` - Sets the maximum number of suggestions to be retrieved from each individual shard. During the reduce phase only the top N suggestions are returned based on the `size` option. Defaults to the `size` option. Setting this to a value higher than the `size` can be useful in order to get a more accurate document frequency for spelling corrections at the cost of performance. Due to the fact that terms are partitioned amongst shards, the shard level document frequencies of spelling corrections may not be precise. Increasing this will make these document frequencies more precise. * `max_inspections` - A factor that is used to multiply with the `shards_size` in order to inspect more candidate spell corrections on the shard level. Can improve accuracy at the cost of performance. Defaults to 5. * `threshold_frequency` - The minimal threshold in number of documents a suggestion should appear in. This can be specified as an absolute number or as a relative percentage of number of documents. This can improve quality by only suggesting high frequency terms. Defaults to 0f and is not enabled. If a value higher than 1 is specified then the number cannot be fractional. The shard level document frequencies are used for this option. * `max_query_frequency` - The maximum threshold in number of documents a sugges text token can exist in order to be included. Can be a relative percentage number (e.g 0.4) or an absolute number to represent document frequencies. If an value higher than 1 is specified then fractional can not be specified. Defaults to 0.01f. This can be used to exclude high frequency terms from being spellchecked. High frequency terms are usually spelled correctly on top of this this also improves the spellcheck performance. The shard level document frequencies are used for this option. |
||
---|---|---|
bin | ||
config | ||
lib/sigar | ||
src | ||
.gitignore | ||
.travis.yml | ||
LICENSE.txt | ||
NOTICE.txt | ||
README.textile | ||
pom.xml |
README.textile
h1. ElasticSearch h2. A Distributed RESTful Search Engine h3. "http://www.elasticsearch.org":http://www.elasticsearch.org ElasticSearch is a distributed RESTful search engine built for the cloud. Features include: * Distributed and Highly Available Search Engine. ** Each index is fully sharded with a configurable number of shards. ** Each shard can have one or more replicas. ** Read / Search operations performed on either one of the replica shard. * Multi Tenant with Multi Types. ** Support for more than one index. ** Support for more than one type per index. ** Index level configuration (number of shards, index storage, ...). * Various set of APIs ** HTTP RESTful API ** Native Java API. ** All APIs perform automatic node operation rerouting. * Document oriented ** No need for upfront schema definition. ** Schema can be defined per type for customization of the indexing process. * Reliable, Asynchronous Write Behind for long term persistency. * (Near) Real Time Search. * Built on top of Lucene ** Each shard is a fully functional Lucene index ** All the power of Lucene easily exposed through simple configuration / plugins. * Per operation consistency ** Single document level operations are atomic, consistent, isolated and durable. * Open Source under Apache 2 License. h2. Getting Started First of all, DON'T PANIC. It will take 5 minutes to get the gist of what ElasticSearch is all about. h3. Installation * "Download":http://www.elasticsearch.org/download and unzip the ElasticSearch official distribution. * Run @bin/elasticsearch -f@ on unix, or @bin/elasticsearch.bat@ on windows. * Run @curl -X GET http://localhost:9200/@. * Start more servers ... h3. Indexing Lets try and index some twitter like information. First, lets create a twitter user, and add some tweets (the @twitter@ index will be created automatically): <pre> curl -XPUT 'http://localhost:9200/twitter/user/kimchy' -d '{ "name" : "Shay Banon" }' curl -XPUT 'http://localhost:9200/twitter/tweet/1' -d ' { "user": "kimchy", "postDate": "2009-11-15T13:12:00", "message": "Trying out Elastic Search, so far so good?" }' curl -XPUT 'http://localhost:9200/twitter/tweet/2' -d ' { "user": "kimchy", "postDate": "2009-11-15T14:12:12", "message": "Another tweet, will it be indexed?" }' </pre> Now, lets see if the information was added by GETting it: <pre> curl -XGET 'http://localhost:9200/twitter/user/kimchy?pretty=true' curl -XGET 'http://localhost:9200/twitter/tweet/1?pretty=true' curl -XGET 'http://localhost:9200/twitter/tweet/2?pretty=true' </pre> h3. Searching Mmm search..., shouldn't it be elastic? Lets find all the tweets that @kimchy@ posted: <pre> curl -XGET 'http://localhost:9200/twitter/tweet/_search?q=user:kimchy&pretty=true' </pre> We can also use the JSON query language ElasticSearch provides instead of a query string: <pre> curl -XGET 'http://localhost:9200/twitter/tweet/_search?pretty=true' -d ' { "query" : { "text" : { "user": "kimchy" } } }' </pre> Just for kicks, lets get all the documents stored (we should see the user as well): <pre> curl -XGET 'http://localhost:9200/twitter/_search?pretty=true' -d ' { "query" : { "matchAll" : {} } }' </pre> We can also do range search (the @postDate@ was automatically identified as date) <pre> curl -XGET 'http://localhost:9200/twitter/_search?pretty=true' -d ' { "query" : { "range" : { "postDate" : { "from" : "2009-11-15T13:00:00", "to" : "2009-11-15T14:00:00" } } } }' </pre> There are many more options to perform search, after all, its a search product no? All the familiar Lucene queries are available through the JSON query language, or through the query parser. h3. Multi Tenant - Indices and Types Maan, that twitter index might get big (in this case, index size == valuation). Lets see if we can structure our twitter system a bit differently in order to support such large amount of data. ElasticSearch support multiple indices, as well as multiple types per index. In the previous example we used an index called @twitter@, with two types, @user@ and @tweet@. Another way to define our simple twitter system is to have a different index per user (though note that an index has an overhead). Here is the indexing curl's in this case: <pre> curl -XPUT 'http://localhost:9200/kimchy/info/1' -d '{ "name" : "Shay Banon" }' curl -XPUT 'http://localhost:9200/kimchy/tweet/1' -d ' { "user": "kimchy", "postDate": "2009-11-15T13:12:00", "message": "Trying out Elastic Search, so far so good?" }' curl -XPUT 'http://localhost:9200/kimchy/tweet/2' -d ' { "user": "kimchy", "postDate": "2009-11-15T14:12:12", "message": "Another tweet, will it be indexed?" }' </pre> The above index information into the @kimchy@ index, with two types, @info@ and @tweet@. Each user will get his own special index. Complete control on the index level is allowed. As an example, in the above case, we would want to change from the default 5 shards with 1 replica per index, to only 1 shard with 1 replica per index (== per twitter user). Here is how this can be done (the configuration can be in yaml as well): <pre> curl -XPUT http://localhost:9200/another_user/ -d ' { "index" : { "numberOfShards" : 1, "numberOfReplicas" : 1 } }' </pre> Search (and similar operations) are multi index aware. This means that we can easily search on more than one index (twitter user), for example: <pre> curl -XGET 'http://localhost:9200/kimchy,another_user/_search?pretty=true' -d ' { "query" : { "matchAll" : {} } }' </pre> Or on all the indices: <pre> curl -XGET 'http://localhost:9200/_search?pretty=true' -d ' { "query" : { "matchAll" : {} } }' </pre> {One liner teaser}: And the cool part about that? You can easily search on multiple twitter users (indices), with different boost levels per user (index), making social search so much simpler (results from my friends rank higher than results from my friends friends). h3. Distributed, Highly Available Lets face it, things will fail.... ElasticSearch is a highly available and distributed search engine. Each index is broken down into shards, and each shard can have one or more replica. By default, an index is created with 5 shards and 1 replica per shard (5/1). There are many topologies that can be used, including 1/10 (improve search performance), or 20/1 (improve indexing performance, with search executed in a map reduce fashion across shards). In order to play with Elastic Search distributed nature, simply bring more nodes up and shut down nodes. The system will continue to serve requests (make sure you use the correct http port) with the latest data indexed. h3. Where to go from here? We have just covered a very small portion of what ElasticSearch is all about. For more information, please refer to: . h3. Building from Source ElasticSearch uses "Maven":http://maven.apache.org for its build system. In order to create a distribution, simply run the @mvn package -DskipTests@ command in the cloned directory. The distribution will be created under @target/releases@. h1. License <pre> This software is licensed under the Apache 2 license, quoted below. Copyright 2009-2012 Shay Banon and ElasticSearch <http://www.elasticsearch.org> Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. </pre>