update readme file

This commit is contained in:
kimchy 2010-03-06 22:41:28 +02:00
parent 290ecd4c95
commit 54dc5a59b1
1 changed files with 71 additions and 28 deletions

View File

@ -46,21 +46,29 @@ 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/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/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?" }'
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 -X GET http://localhost:9200/twitter/user/kimchy?pretty=true
curl -X GET http://localhost:9200/twitter/tweet/1?pretty=true
curl -X GET http://localhost:9200/twitter/tweet/2?pretty=true
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
@ -69,28 +77,42 @@ 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
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 -XPOST http://localhost:9200/twitter/tweet/_search?pretty=true -d \
'{ query : { term : { user: "kimchy" } } }'
curl -XGET 'http://localhost:9200/twitter/tweet/_search?pretty=true' -d '
{
"query" : {
"term" : { "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 : {} } }'
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" } } } }'
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.
@ -104,13 +126,21 @@ ElasticSearch support multiple indices, as well as multiple types per index. In
Another way to define our simple twitter system is to have a different index per user. 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/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/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?" }'
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.
@ -118,23 +148,36 @@ The above index information into the @kimchy@ index, with two types, @info@ and
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 } }'
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 : {} } }'
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 : {} } }'
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).
@ -165,14 +208,14 @@ We have just covered a very small portion of what ElasticSearch is all about. Fo
h3. Building from Source
ElasticSearch uses Gradle:http://www.gradle.org for its build system. In order to create a distribution, simply run @gradlew devRelease@, the distribution will be created under @build/distributions@.
ElasticSearch uses Gradle:http://www.gradle.org for its build system. In order to create a distribution, simply run @gradlew@, the distribution will be created under @build/distributions@.
h1. License
<pre>
This software is licensed under the Apache 2 license, quoted below.
Copyright 2009-2010 Elastic Search <http://www.elasticsearch.com>
Copyright 2009-2010 Shay Banon and ElasticSearch <http://www.elasticsearch.com>
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