# Help: Beginners Guide needed

**URL:** <https://discuss.elastic.co/t/help-beginners-guide-needed/7724>\
**Category:** Elasticsearch\
**Created:** [May 16, 2012, 4:53pm UTC](https://discuss.elastic.co/t/help-beginners-guide-needed/7724 "2012-05-16T16:53:08Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thorsten](https://avatars.discourse-cdn.com/v4/letter/t/d2c977/32.png) [@Thorsten](https://discuss.elastic.co/u/Thorsten)\
**Post date:** [May 16, 2012, 4:53pm UTC](https://discuss.elastic.co/t/help-beginners-guide-needed/7724/1 "2012-05-16T16:53:08Z")

</div>

Hi there,  
I'm looking for a dead simple, step by step explanation of how to get  
started with elaticsearch.

What I've done so far:

I went through the examples on the github readme, and created the twitter  
items.

curl -XPUT '[http://localhost:9200/twitter/user/kimchy](http://localhost:9200/twitter/user/kimchy)' -d '{ "name" : "Shay  
Banon" }'  
curl -XPUT '[http://localhost:9200/twitter/tweet/1](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](http://localhost:9200/twitter/tweet/2)' -d '  
{  
"user": "kimchy",  
"postDate": "2009-11-15T14:12:12",  
"message": "Another tweet, will it be indexed?"  
}'

What I want to do:

Add an extra field "location" to the tweets, and make it a geo\_point.

curl -XPUT '[http://localhost:9200/twitter/tweet/1](http://localhost:9200/twitter/tweet/1)' -d '  
{  
"user": "kimchy",  
"postDate": "2009-11-15T13:12:00",  
"message": "Trying out Elastic Search, so far so good?",  
"location" : {  
"lat" : 41.12,  
"lon" : 8.21  
}  
}'

curl -XPUT '[http://localhost:9200/twitter/tweet/2](http://localhost:9200/twitter/tweet/2)' -d '  
{  
"user": "kimchy",  
"postDate": "2009-11-15T14:12:12",  
"message": "Another tweet, will it be indexed?" ,  
"location" : {  
"lat" : 50.12,  
"lon" : 8.34  
}  
}'

I tried adding a mapping, but it does not seem to work.

curl -XPUT '[http://localhost:9200/twitter/tweet/\_mapping](http://localhost:9200/twitter/tweet/_mapping)' -d '  
{  
"properties" : {  
"location" : {  
"type" : "geo\_point"  
}  
}  
}  
'

When I try to filter the results, still all tweets are returned, no matter  
how close I set the distance in the filter.

{  
"filtered" : {  
"query" : {  
"match\_all" : {}  
},  
"filter" : {  
"geo\_distance" : {  
"distance" : "2km",  
"tweet.location" : {  
"lat" : 30.00,  
"lon" : 50.00  
}  
}  
}  
}  
}

What am I doing wrong? Thanks for your help

Thorsten

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [May 16, 2012, 4:57pm UTC](https://discuss.elastic.co/t/help-beginners-guide-needed/7724/2 "2012-05-16T16:57:15Z")

</div>

You cannot change a field's type after a document with that field has  
been indexed. Try explicitly creating the index first with that  
mapping, then add your documents.

--  
Ivan

On Wed, May 16, 2012 at 9:53 AM, Thorsten [thorsten1983@googlemail.com](mailto:thorsten1983@googlemail.com) wrote:

> Hi there,  
> I'm looking for a dead simple, step by step explanation of how to get  
> started with elaticsearch.
> 
> What I've done so far:
> 
> I went through the examples on the github readme, and created the twitter  
> items.
> 
> curl -XPUT '[http://localhost:9200/twitter/user/kimchy](http://localhost:9200/twitter/user/kimchy)' -d '{ "name" : "Shay  
> Banon" }'  
> curl -XPUT '[http://localhost:9200/twitter/tweet/1](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](http://localhost:9200/twitter/tweet/2)' -d '  
> {  
> "user": "kimchy",  
> "postDate": "2009-11-15T14:12:12",  
> "message": "Another tweet, will it be indexed?"  
> }'
> 
> What I want to do:
> 
> Add an extra field "location" to the tweets, and make it a geo\_point.
> 
> curl -XPUT '[http://localhost:9200/twitter/tweet/1](http://localhost:9200/twitter/tweet/1)' -d '  
> {  
> "user": "kimchy",  
> "postDate": "2009-11-15T13:12:00",  
> "message": "Trying out Elastic Search, so far so good?",  
> "location" : {  
> "lat" : 41.12,  
> "lon" : 8.21  
> }  
> }'
> 
> curl -XPUT '[http://localhost:9200/twitter/tweet/2](http://localhost:9200/twitter/tweet/2)' -d '  
> {  
> "user": "kimchy",  
> "postDate": "2009-11-15T14:12:12",  
> "message": "Another tweet, will it be indexed?" ,  
> "location" : {  
> "lat" : 50.12,  
> "lon" : 8.34  
> }  
> }'
> 
> I tried adding a mapping, but it does not seem to work.
> 
> curl -XPUT '[http://localhost:9200/twitter/tweet/\_mapping](http://localhost:9200/twitter/tweet/_mapping)' -d '  
> {  
> "properties" : {  
> "location" : {  
> "type" : "geo\_point"  
> }  
> }  
> }  
> '
> 
> When I try to filter the results, still all tweets are returned, no matter  
> how close I set the distance in the filter.
> 
> {  
> "filtered" : {  
> "query" : {  
> "match\_all" : {}  
> },  
> "filter" : {  
> "geo\_distance" : {  
> "distance" : "2km",  
> "tweet.location" : {  
> "lat" : 30.00,  
> "lon" : 50.00  
> }  
> }  
> }  
> }  
> }
> 
> What am I doing wrong? Thanks for your help
> 
> Thorsten

---

<div class="post-metadata">

**Author:** ![Thorsten](https://avatars.discourse-cdn.com/v4/letter/t/d2c977/32.png) [@Thorsten](https://discuss.elastic.co/u/Thorsten)\
**Post date:** [May 16, 2012, 5:25pm UTC](https://discuss.elastic.co/t/help-beginners-guide-needed/7724/3 "2012-05-16T17:25:40Z")

</div>

I'm sorry, but it seems I need it more fool-prove 😉

I reseted elasticsearch, and tried to follow the docs[http://www.elasticsearch.org/guide/reference/api/admin-indices-create-index.html](http://www.elasticsearch.org/guide/reference/api/admin-indices-create-index.html) but  
I'm a bit confused with how to edit the code given there:

curl -XPOST localhost:9200/test -d '{  
"settings" : {  
"number\_of\_shards" : 1  
},  
"mappings" : {  
"type1" : {  
"\_source" : { "enabled" : false },  
"properties" : {  
"field1" : { "type" : "string", "index" : "not\_analyzed" }  
}  
}  
}  
}'

I removed the "settings" and "\_source":

curl -XPOST localhost:9200/twitter/tweet -d '{  
"mappings" : {  
"type1" : {  
"properties" : {  
"location" : {  
"type" : "geo\_point"  
}  
}  
}  
}  
}'

And entered the tweets again, but no luck with geo filtering.

Do I need to change "type1" as well? And if so, into what?

I might appear stupid, but the docs aren't quite clear to me... ☹

Thanks

Am Mittwoch, 16. Mai 2012 18:57:15 UTC+2 schrieb Ivan Brusic:

> You cannot change a field's type after a document with that field has  
> been indexed. Try explicitly creating the index first with that  
> mapping, then add your documents.
> 
> --  
> Ivan
> 
> On Wed, May 16, 2012 at 9:53 AM, Thorsten wrote:
> 
> > Hi there,  
> > I'm looking for a dead simple, step by step explanation of how to get  
> > started with elaticsearch.
> > 
> > What I've done so far:
> > 
> > I went through the examples on the github readme, and created the  
> > twitter  
> > items.
> > 
> > curl -XPUT '[http://localhost:9200/twitter/user/kimchy](http://localhost:9200/twitter/user/kimchy)' -d '{ "name" :  
> > "Shay  
> > Banon" }'  
> > curl -XPUT '[http://localhost:9200/twitter/tweet/1](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](http://localhost:9200/twitter/tweet/2)' -d '  
> > {  
> > "user": "kimchy",  
> > "postDate": "2009-11-15T14:12:12",  
> > "message": "Another tweet, will it be indexed?"  
> > }'
> > 
> > What I want to do:
> > 
> > Add an extra field "location" to the tweets, and make it a geo\_point.
> > 
> > curl -XPUT '[http://localhost:9200/twitter/tweet/1](http://localhost:9200/twitter/tweet/1)' -d '  
> > {  
> > "user": "kimchy",  
> > "postDate": "2009-11-15T13:12:00",  
> > "message": "Trying out Elastic Search, so far so good?",  
> > "location" : {  
> > "lat" : 41.12,  
> > "lon" : 8.21  
> > }  
> > }'
> > 
> > curl -XPUT '[http://localhost:9200/twitter/tweet/2](http://localhost:9200/twitter/tweet/2)' -d '  
> > {  
> > "user": "kimchy",  
> > "postDate": "2009-11-15T14:12:12",  
> > "message": "Another tweet, will it be indexed?" ,  
> > "location" : {  
> > "lat" : 50.12,  
> > "lon" : 8.34  
> > }  
> > }'
> > 
> > I tried adding a mapping, but it does not seem to work.
> > 
> > curl -XPUT '[http://localhost:9200/twitter/tweet/\_mapping](http://localhost:9200/twitter/tweet/_mapping)' -d '  
> > {  
> > "properties" : {  
> > "location" : {  
> > "type" : "geo\_point"  
> > }  
> > }  
> > }  
> > '
> > 
> > When I try to filter the results, still all tweets are returned, no  
> > matter  
> > how close I set the distance in the filter.
> > 
> > {  
> > "filtered" : {  
> > "query" : {  
> > "match\_all" : {}  
> > },  
> > "filter" : {  
> > "geo\_distance" : {  
> > "distance" : "2km",  
> > "tweet.location" : {  
> > "lat" : 30.00,  
> > "lon" : 50.00  
> > }  
> > }  
> > }  
> > }  
> > }
> > 
> > What am I doing wrong? Thanks for your help
> > 
> > Thorsten

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [May 16, 2012, 5:28pm UTC](https://discuss.elastic.co/t/help-beginners-guide-needed/7724/4 "2012-05-16T17:28:25Z")

</div>

In your case, type1 should be tweet.

On Wed, May 16, 2012 at 10:25 AM, Thorsten [thorsten1983@googlemail.com](mailto:thorsten1983@googlemail.com) wrote:

> I'm sorry, but it seems I need it more fool-prove 😉
> 
> I reseted elasticsearch, and tried to follow the docs but I'm a bit confused  
> with how to edit the code given there:
> 
> curl -XPOST localhost:9200/test -d '{  
> "settings" : {  
> "number\_of\_shards" : 1  
> },  
> "mappings" : {  
> "type1" : {  
> "\_source" : { "enabled" : false },  
> "properties" : {  
> "field1" : { "type" : "string", "index" : "not\_analyzed" }  
> }  
> }  
> }  
> }'
> 
> I removed the "settings" and "\_source":
> 
> curl -XPOST localhost:9200/twitter/tweet -d '{  
> "mappings" : {  
> "type1" : {  
> "properties" : {  
> "location" : {  
> "type" : "geo\_point"  
> }  
> }  
> }  
> }  
> }'
> 
> And entered the tweets again, but no luck with geo filtering.
> 
> Do I need to change "type1" as well? And if so, into what?
> 
> I might appear stupid, but the docs aren't quite clear to me... ☹
> 
> Thanks
> 
> Am Mittwoch, 16. Mai 2012 18:57:15 UTC+2 schrieb Ivan Brusic:
> 
> > You cannot change a field's type after a document with that field has  
> > been indexed. Try explicitly creating the index first with that  
> > mapping, then add your documents.
> > 
> > --  
> > Ivan
> > 
> > On Wed, May 16, 2012 at 9:53 AM, Thorsten wrote:
> > 
> > > Hi there,  
> > > I'm looking for a dead simple, step by step explanation of how to get  
> > > started with elaticsearch.
> > > 
> > > What I've done so far:
> > > 
> > > I went through the examples on the github readme, and created the  
> > > twitter  
> > > items.
> > > 
> > > curl -XPUT '[http://localhost:9200/twitter/user/kimchy](http://localhost:9200/twitter/user/kimchy)' -d '{ "name" :  
> > > "Shay  
> > > Banon" }'  
> > > curl -XPUT '[http://localhost:9200/twitter/tweet/1](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](http://localhost:9200/twitter/tweet/2)' -d '  
> > > {  
> > > "user": "kimchy",  
> > > "postDate": "2009-11-15T14:12:12",  
> > > "message": "Another tweet, will it be indexed?"  
> > > }'
> > > 
> > > What I want to do:
> > > 
> > > Add an extra field "location" to the tweets, and make it a geo\_point.
> > > 
> > > curl -XPUT '[http://localhost:9200/twitter/tweet/1](http://localhost:9200/twitter/tweet/1)' -d '  
> > > {  
> > > "user": "kimchy",  
> > > "postDate": "2009-11-15T13:12:00",  
> > > "message": "Trying out Elastic Search, so far so good?",  
> > > "location" : {  
> > > "lat" : 41.12,  
> > > "lon" : 8.21  
> > > }  
> > > }'
> > > 
> > > curl -XPUT '[http://localhost:9200/twitter/tweet/2](http://localhost:9200/twitter/tweet/2)' -d '  
> > > {  
> > > "user": "kimchy",  
> > > "postDate": "2009-11-15T14:12:12",  
> > > "message": "Another tweet, will it be indexed?" ,  
> > > "location" : {  
> > > "lat" : 50.12,  
> > > "lon" : 8.34  
> > > }  
> > > }'
> > > 
> > > I tried adding a mapping, but it does not seem to work.
> > > 
> > > curl -XPUT '[http://localhost:9200/twitter/tweet/\_mapping](http://localhost:9200/twitter/tweet/_mapping)' -d '  
> > > {  
> > > "properties" : {  
> > > "location" : {  
> > > "type" : "geo\_point"  
> > > }  
> > > }  
> > > }  
> > > '
> > > 
> > > When I try to filter the results, still all tweets are returned, no  
> > > matter  
> > > how close I set the distance in the filter.
> > > 
> > > {  
> > > "filtered" : {  
> > > "query" : {  
> > > "match\_all" : {}  
> > > },  
> > > "filter" : {  
> > > "geo\_distance" : {  
> > > "distance" : "2km",  
> > > "tweet.location" : {  
> > > "lat" : 30.00,  
> > > "lon" : 50.00  
> > > }  
> > > }  
> > > }  
> > > }  
> > > }
> > > 
> > > What am I doing wrong? Thanks for your help
> > > 
> > > Thorsten

---

<div class="post-metadata">

**Author:** ![Thorsten](https://avatars.discourse-cdn.com/v4/letter/t/d2c977/32.png) [@Thorsten](https://discuss.elastic.co/u/Thorsten)\
**Post date:** [May 16, 2012, 5:55pm UTC](https://discuss.elastic.co/t/help-beginners-guide-needed/7724/5 "2012-05-16T17:55:08Z")

</div>

I've done that as well now, but no success.

Looking at the mappings, the mapping is not listed as "geo".

curl -XGET '[http://localhost:9200/twitter/tweet/\_mapping?pretty=true](http://localhost:9200/twitter/tweet/_mapping?pretty=true)'  
{  
"tweet" : {  
"properties" : {  
"location" : {  
"dynamic" : "true",  
"properties" : {  
"lat" : {  
"type" : "double"  
},  
"lon" : {  
"type" : "double"  
}  
}  
},  
"mappings" : {  
"dynamic" : "true",  
"properties" : {  
"tweet" : {  
"dynamic" : "true",  
"properties" : {  
"properties" : {  
"dynamic" : "true",  
"properties" : {  
"location" : {  
"dynamic" : "true",  
"properties" : {  
"type" : {  
"type" : "string"  
}  
}  
}  
}  
}  
}  
}  
}  
},  
"message" : {  
"type" : "string"  
},  
"postDate" : {  
"type" : "date",  
"format" : "dateOptionalTime"  
},  
"user" : {  
"type" : "string"  
}  
}  
}  
}

BTW: How can I get rid of my email appearing in these posts? Thats not  
quite helpful from google for preventing spam...

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [May 16, 2012, 6:18pm UTC](https://discuss.elastic.co/t/help-beginners-guide-needed/7724/6 "2012-05-16T18:18:00Z")

</div>

Not quite there. 🙂

Your mapping is way off. It looks like your post a mapping as a  
document. The "property property" is a good indication:

"dynamic" : "true",  
"properties" : {  
"properties" : {  
"dynamic" : "true",

Your put mapping is missing \_mapping  
curl -XPOST localhost:9200/twitter/tweet -d '{  
"mappings" : {

I do not use the REST API for mappings, but it should look like this  
example: [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/admin-indices-put-mapping.html)

--  
Ivan

On Wed, May 16, 2012 at 10:55 AM, Thorsten [thorsten1983@googlemail.com](mailto:thorsten1983@googlemail.com) wrote:

> I've done that as well now, but no success.
> 
> Looking at the mappings, the mapping is not listed as "geo".
> 
> curl -XGET '[http://localhost:9200/twitter/tweet/\_mapping?pretty=true](http://localhost:9200/twitter/tweet/_mapping?pretty=true)'  
> {  
> "tweet" : {  
> "properties" : {  
> "location" : {  
> "dynamic" : "true",  
> "properties" : {  
> "lat" : {  
> "type" : "double"  
> },  
> "lon" : {  
> "type" : "double"  
> }  
> }  
> },  
> "mappings" : {  
> "dynamic" : "true",  
> "properties" : {  
> "tweet" : {  
> "dynamic" : "true",  
> "properties" : {  
> "properties" : {  
> "dynamic" : "true",  
> "properties" : {  
> "location" : {  
> "dynamic" : "true",  
> "properties" : {  
> "type" : {  
> "type" : "string"  
> }  
> }  
> }  
> }  
> }  
> }  
> }  
> }  
> },  
> "message" : {  
> "type" : "string"  
> },  
> "postDate" : {  
> "type" : "date",  
> "format" : "dateOptionalTime"  
> },  
> "user" : {  
> "type" : "string"  
> }  
> }  
> }  
> }
> 
> BTW: How can I get rid of my email appearing in these posts? Thats not quite  
> helpful from google for preventing spam...

---

<div class="post-metadata">

**Author:** ![Thorsten](https://avatars.discourse-cdn.com/v4/letter/t/d2c977/32.png) [@Thorsten](https://discuss.elastic.co/u/Thorsten)\
**Post date:** [May 16, 2012, 6:51pm UTC](https://discuss.elastic.co/t/help-beginners-guide-needed/7724/7 "2012-05-16T18:51:26Z")

</div>

Thanks a lot for your patience, got it working now 😃

For all others who are interested, here's the summary:

_HowTo: Elasticsearch with GeoData:_

_1. Create empty index "twitter"_

curl -XPUT '[http://localhost:9200/twitter/](http://localhost:9200/twitter/)'

_2. create geo\_point mapping for the actual "tweet"_

curl -XPUT '[http://localhost:9200/twitter/tweet/\_mapping](http://localhost:9200/twitter/tweet/_mapping)' -d '  
{  
"tweet" : {  
"properties" : {  
"location" : {"type" : "geo\_point"}  
}  
}  
}'

_3. Let's check if the mapping was set_

curl -XGET '[http://localhost:9200/twitter/tweet/\_mapping?pretty=true](http://localhost:9200/twitter/tweet/_mapping?pretty=true)'

(should return ..."location: type: geo\_point"...)

_4. Post some tweets, with geo data_

curl -XPUT '[http://localhost:9200/twitter/tweet/1](http://localhost:9200/twitter/tweet/1)' -d '  
{  
"user": "kimchy",  
"postDate": "2009-11-15T13:12:00",  
"message": "Trying out Elastic Search, so far so good?",  
"location" : {  
"lat" : 41.12,  
"lon" : 8.21  
}  
}'

curl -XPUT '[http://localhost:9200/twitter/tweet/2](http://localhost:9200/twitter/tweet/2)' -d '  
{  
"user": "kimchy",  
"postDate": "2009-11-15T14:12:12",  
"message": "Another tweet, will it be indexed?" ,  
"location" : {  
"lat" : 50.12,  
"lon" : 8.34  
}  
}'

_5.a) Filter by distance_

curl -XGET '[http://localhost:9200/twitter/tweet/\_search](http://localhost:9200/twitter/tweet/_search)' -d '{  
"query": {  
"filtered" : {  
"query" : {  
"match\_all" : {}  
},  
"filter" : {  
"geo\_distance" : {  
"distance" : "200km",  
"tweet.location" : {  
"lat" : 40.00,  
"lon" : 8.00  
}  
}  
}  
}  
}  
}'

_5.b) sort by distance, and get distance value back in results_

curl -XGET '[http://localhost:9200/twitter/tweet/\_search](http://localhost:9200/twitter/tweet/_search)' -d '{  
"sort" : [  
{  
"\_geo\_distance" : {  
"tweet.location" : {  
"lat" : 41,  
"lon" : 8  
},  
"order" : "asc",  
"unit" : "km"  
}  
}  
],  
"query" : {  
"match\_all" : {}  
}  
}'

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 3:28am UTC](https://discuss.elastic.co/t/help-beginners-guide-needed/7724/8 "2017-07-06T03:28:31Z")

</div>


