# Help with setting up mappings (Perl)

**URL:** <https://discuss.elastic.co/t/help-with-setting-up-mappings-perl/16267>\
**Category:** Elasticsearch\
**Created:** [March 10, 2014, 2:35pm UTC](https://discuss.elastic.co/t/help-with-setting-up-mappings-perl/16267 "2014-03-10T14:35:21Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dominic\_Nicholas](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dominic_nicholas/32/718_2.png) [@Dominic\_Nicholas](https://discuss.elastic.co/u/Dominic_Nicholas)\
**Post date:** [March 10, 2014, 2:35pm UTC](https://discuss.elastic.co/t/help-with-setting-up-mappings-perl/16267/1 "2014-03-10T14:35:21Z")

</div>

Hi,

I'm using the Elasticsearch Perl module and need guidance on setting up  
mappings.  
I'm using the bulk() method to index data. Here is an example of the  
structure of the data :

$response = $e-\>bulk(  
"index" : "idx-2014.03.10",  
"type" : "my\_type",  
"body" : [  
{  
"index" : {  
"\_index" : "idx-2014.03.10",  
"\_id" : "4410",  
"\_type" : "my\_type"  
}  
},  
{  
"something" : "interesting",  
"somethingelse" : "also interesting"  
},  
{  
"index" : {  
"\_index" : "idx-2014.03.10",  
"\_id" : "4411",  
"\_type" : "my\_type"  
}  
},  
{  
"something" : "very interesting",  
"somethingelse" : "not interesting"  
}  
]  
);

How do I set up mappings on various fields in the above example for  
'something' and 'somethingelse' fields ?  
Also, how do I turn off the analyzer for an index (index: not\_analyzed)  
too ?

I know there are several ways of setting up mappings such as :

- when creating an index
- by using the dedicated update mapping api
- using index templates

Ideally I'd like to use the dedicated update mapping api but am unclear how  
to use that through the Perl library interface (eg use transport-\>perform\_request()  
?).

Thanks for any guidance and help.

Dom

--  
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 [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/f310961e-c389-49ea-82c9-c47d71d32209%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/f310961e-c389-49ea-82c9-c47d71d32209%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [March 10, 2014, 2:52pm UTC](https://discuss.elastic.co/t/help-with-setting-up-mappings-perl/16267/2 "2014-03-10T14:52:48Z")

</div>

Hi Dom

First, make sure you're using the new Search::Elasticsearch client  
[Search::Elasticsearch - The official client for Elasticsearch - metacpan.org](https://metacpan.org/pod/Search::Elasticsearch) - we've just renamed it to  
avoid namespace clashes with older clients.

Then: to configure the mapping yourself, you need to do it before you index  
any data (using the bulk method or any other indexing method).

The full Elasticsearch REST API is supported by the Perl client, eg:

1. at index creation time:

See  
[https://metacpan.org/pod/Search::Elasticsearch::Client::Direct::Indices#create](https://metacpan.org/pod/Search::Elasticsearch::Client::Direct::Indices#create)

1. Update mapping API (note, you can't change existing mappings, just add  
new fields/types):

See  
[https://metacpan.org/pod/Search::Elasticsearch::Client::Direct::Indices#put\_mapping](https://metacpan.org/pod/Search::Elasticsearch::Client::Direct::Indices#put_mapping)

clint

On 10 March 2014 15:35, Dominic Nicholas [dominic.s.nicholas@gmail.com](mailto:dominic.s.nicholas@gmail.com)wrote:

> Hi,
> 
> I'm using the Elasticsearch Perl module and need guidance on setting up  
> mappings.  
> I'm using the bulk() method to index data. Here is an example of the  
> structure of the data :
> 
> $response = $e-\>bulk(  
> "index" : "idx-2014.03.10",  
> "type" : "my\_type",  
> "body" : [  
> {  
> "index" : {  
> "\_index" : "idx-2014.03.10",  
> "\_id" : "4410",  
> "\_type" : "my\_type"  
> }  
> },  
> {  
> "something" : "interesting",  
> "somethingelse" : "also interesting"  
> },  
> {  
> "index" : {  
> "\_index" : "idx-2014.03.10",  
> "\_id" : "4411",  
> "\_type" : "my\_type"  
> }  
> },  
> {  
> "something" : "very interesting",  
> "somethingelse" : "not interesting"  
> }  
> ]  
> );
> 
> How do I set up mappings on various fields in the above example for  
> 'something' and 'somethingelse' fields ?  
> Also, how do I turn off the analyzer for an index (index: not\_analyzed)  
> too ?
> 
> I know there are several ways of setting up mappings such as :
> 
> - when creating an index
> - by using the dedicated update mapping api
> - using index templates
> 
> Ideally I'd like to use the dedicated update mapping api but am unclear  
> how to use that through the Perl library interface (eg use transport-\>perform\_request()  
> ?).
> 
> Thanks for any guidance and help.
> 
> Dom
> 
> --  
> 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 [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/f310961e-c389-49ea-82c9-c47d71d32209%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/f310961e-c389-49ea-82c9-c47d71d32209%40googlegroups.com)[https://groups.google.com/d/msgid/elasticsearch/f310961e-c389-49ea-82c9-c47d71d32209%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/f310961e-c389-49ea-82c9-c47d71d32209%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](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 [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAPt3XKQhLPNsGhugoaYqWisBuKRp73oD%2BHcRDi2GE85iH8MrpA%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAPt3XKQhLPNsGhugoaYqWisBuKRp73oD%2BHcRDi2GE85iH8MrpA%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Dominic\_Nicholas](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dominic_nicholas/32/718_2.png) [@Dominic\_Nicholas](https://discuss.elastic.co/u/Dominic_Nicholas)\
**Post date:** [March 10, 2014, 5:45pm UTC](https://discuss.elastic.co/t/help-with-setting-up-mappings-perl/16267/3 "2014-03-10T17:45:33Z")

</div>

Hi Clinton,

I really appreciate the fast reply. We're now using Search::Elasticsearch.  
I'm still having a problem getting mappings set and hope you can help.  
What I'm trying to do is turn of the analyzer for certain fields. Here is  
what I have :

In Perl :

```
%mappings = (  
                'index' => 'idx-2014.03.10',
                'type' => 'my_type',
                'body' => {
                                    'my_type' => {
                                        "properties" => {
                                            'somefield' => 

```

'not\_analyzed'  
}  
}  
}  
);

```
eval { $es_result = $elastic_search_object->indices->put_mapping( 

```

%mappings ) ; };  
etc etc

The put\_mapping call does not return an error.

In JSON format, the mappings hash is :

```
{
   "index" : "idx-2014.03.10",
   "type" : "my_type"
   "body" : {
      "my_type" : {
         "properties" : {
            "somefield" : "not_analyzed"
         }
      }
   }    
}

```

When I try to get the mappings for the this type/index with :

```
curl -XGET 'localhost:9200/idx-2014.03.10/my_type/_mapping'

```

I get {} which I think means there are no mappings yet set for this index  
and type.

Is the body section above of the correct structure ? Is 'properties' always  
required ? Any guidance would be much appreciated again.

## I've been using these as guides so far :

[https://metacpan.org/pod/Search::Elasticsearch::Client::Direct::Indices#put\_mapping](https://metacpan.org/pod/Search::Elasticsearch::Client::Direct::Indices#put_mapping)

- [Elastic — The Search AI Company | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-put-mapping.html)
- some training docs

Thanks again  
Dom

On Monday, March 10, 2014 10:35:21 AM UTC-4, Dominic Nicholas wrote:

> Hi,
> 
> I'm using the Elasticsearch Perl module and need guidance on setting up  
> mappings.  
> I'm using the bulk() method to index data. Here is an example of the  
> structure of the data :
> 
> $response = $e-\>bulk(  
> "index" : "idx-2014.03.10",  
> "type" : "my\_type",  
> "body" : [  
> {  
> "index" : {  
> "\_index" : "idx-2014.03.10",  
> "\_id" : "4410",  
> "\_type" : "my\_type"  
> }  
> },  
> {  
> "something" : "interesting",  
> "somethingelse" : "also interesting"  
> },  
> {  
> "index" : {  
> "\_index" : "idx-2014.03.10",  
> "\_id" : "4411",  
> "\_type" : "my\_type"  
> }  
> },  
> {  
> "something" : "very interesting",  
> "somethingelse" : "not interesting"  
> }  
> ]  
> );
> 
> How do I set up mappings on various fields in the above example for  
> 'something' and 'somethingelse' fields ?  
> Also, how do I turn off the analyzer for an index (index: not\_analyzed)  
> too ?
> 
> I know there are several ways of setting up mappings such as :
> 
> - when creating an index
> - by using the dedicated update mapping api
> - using index templates
> 
> Ideally I'd like to use the dedicated update mapping api but am unclear  
> how to use that through the Perl library interface (eg use transport-\>perform\_request()  
> ?).
> 
> Thanks for any guidance and help.
> 
> Dom

--  
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 [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/f23f9a91-3176-4bea-8258-c9d38d1dd34f%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/f23f9a91-3176-4bea-8258-c9d38d1dd34f%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [March 10, 2014, 7:22pm UTC](https://discuss.elastic.co/t/help-with-setting-up-mappings-perl/16267/4 "2014-03-10T19:22:39Z")

</div>

Hi Dom

You need to consult the Elasticsearch documentation for mapping. See

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

What you're looking for is:

```
....
properties => {
    somefield => {
        type => 'string',
        index => 'not_analyzed'
    }
}
....

```

Clint

On 10 March 2014 18:45, Dominic Nicholas [dominic.s.nicholas@gmail.com](mailto:dominic.s.nicholas@gmail.com)wrote:

> Hi Clinton,
> 
> I really appreciate the fast reply. We're now using Search::Elasticsearch.  
> I'm still having a problem getting mappings set and hope you can help.  
> What I'm trying to do is turn of the analyzer for certain fields. Here is  
> what I have :
> 
> In Perl :
> 
> ```
> %mappings = (
> 'index' => 'idx-2014.03.10',
> 'type' => 'my_type',
> 'body' => {
> 'my_type' => {
> "properties" => {
> 'somefield' =>
> 
> ```
> 
> 'not\_analyzed'  
> }  
> }  
> }  
> );
> 
> ```
> eval { $es_result = $elastic_search_object->indices->put_mapping(
> 
> ```
> 
> %mappings ) ; };  
> etc etc
> 
> The put\_mapping call does not return an error.
> 
> In JSON format, the mappings hash is :
> 
> ```
> {
> "index" : "idx-2014.03.10",
> "type" : "my_type"
> "body" : {
> "my_type" : {
> "properties" : {
> "somefield" : "not_analyzed"
> }
> }
> }
> }
> 
> ```
> 
> When I try to get the mappings for the this type/index with :
> 
> ```
> curl -XGET 'localhost:9200/idx-2014.03.10/my_type/_mapping'
> 
> ```
> 
> I get {} which I think means there are no mappings yet set for this index  
> and type.
> 
> Is the body section above of the correct structure ? Is 'properties'  
> always required ? Any guidance would be much appreciated again.
> 
> ## I've been using these as guides so far :
> 
> ## [https://metacpan.org/pod/Search::Elasticsearch::Client::Direct::Indices#put\_mapping](https://metacpan.org/pod/Search::Elasticsearch::Client::Direct::Indices#put_mapping)
> 
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-put-mapping.html)
> 
> - some training docs
> 
> Thanks again  
> Dom
> 
> On Monday, March 10, 2014 10:35:21 AM UTC-4, Dominic Nicholas wrote:
> 
> > Hi,
> > 
> > I'm using the Elasticsearch Perl module and need guidance on setting up  
> > mappings.  
> > I'm using the bulk() method to index data. Here is an example of the  
> > structure of the data :
> > 
> > $response = $e-\>bulk(  
> > "index" : "idx-2014.03.10",  
> > "type" : "my\_type",  
> > "body" : [  
> > {  
> > "index" : {  
> > "\_index" : "idx-2014.03.10",  
> > "\_id" : "4410",  
> > "\_type" : "my\_type"  
> > }  
> > },  
> > {  
> > "something" : "interesting",  
> > "somethingelse" : "also interesting"  
> > },  
> > {  
> > "index" : {  
> > "\_index" : "idx-2014.03.10",  
> > "\_id" : "4411",  
> > "\_type" : "my\_type"  
> > }  
> > },  
> > {  
> > "something" : "very interesting",  
> > "somethingelse" : "not interesting"  
> > }  
> > ]  
> > );
> > 
> > How do I set up mappings on various fields in the above example for  
> > 'something' and 'somethingelse' fields ?  
> > Also, how do I turn off the analyzer for an index (index: not\_analyzed)  
> > too ?
> > 
> > I know there are several ways of setting up mappings such as :
> > 
> > - when creating an index
> > - by using the dedicated update mapping api
> > - using index templates
> > 
> > Ideally I'd like to use the dedicated update mapping api but am unclear  
> > how to use that through the Perl library interface (eg use  
> > transport-\>perform\_request() ?).
> > 
> > Thanks for any guidance and help.
> > 
> > Dom
> > 
> > --  
> > 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 [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/f23f9a91-3176-4bea-8258-c9d38d1dd34f%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/f23f9a91-3176-4bea-8258-c9d38d1dd34f%40googlegroups.com)[https://groups.google.com/d/msgid/elasticsearch/f23f9a91-3176-4bea-8258-c9d38d1dd34f%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/f23f9a91-3176-4bea-8258-c9d38d1dd34f%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > .
> 
> For more options, visit [https://groups.google.com/d/optout](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 [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAPt3XKTT2hw3msuptTr1ir5AR7KBB\_11z1S4\_xOJh38Qui4wCg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAPt3XKTT2hw3msuptTr1ir5AR7KBB_11z1S4_xOJh38Qui4wCg%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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, 1:44am UTC](https://discuss.elastic.co/t/help-with-setting-up-mappings-perl/16267/5 "2017-07-06T01:44:26Z")

</div>


