Help with setting up mappings (Perl)

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

Hi Dom

First, make sure you're using the new Search::Elasticsearch client
Search::Elasticsearch - The official client for Elasticsearch - metacpan.org - 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:

    $es->indices->create(
    index => 'myindex',
    body => {
    mappings=> {
    mytype => {...mapping definition...}
    }
    }
    );

See
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):

    $es->indices->put_mapping(
    index => 'myindex',
    type => 'mytype',
    body => { ... mapping definition ... }
    )

See
https://metacpan.org/pod/Search::Elasticsearch::Client::Direct::Indices#put_mapping

clint

On 10 March 2014 15:35, Dominic Nicholas dominic.s.nicholas@gmail.comwrote:

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.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/f310961e-c389-49ea-82c9-c47d71d32209%40googlegroups.comhttps://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.

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/CAPt3XKQhLPNsGhugoaYqWisBuKRp73oD%2BHcRDi2GE85iH8MrpA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

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

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

Hi Dom

You need to consult the Elasticsearch documentation for mapping. See

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.comwrote:

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

Elasticsearch Platform — Find real-time answers at scale | Elastic

  • 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.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/f23f9a91-3176-4bea-8258-c9d38d1dd34f%40googlegroups.comhttps://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.

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/CAPt3XKTT2hw3msuptTr1ir5AR7KBB_11z1S4_xOJh38Qui4wCg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.