Dynamic Mapping Template

761 views
Skip to first unread message

SkyStebnicki

unread,
Apr 14, 2012, 10:53:28 AM4/14/12
to elastica-...@googlegroups.com
Greetings everyone. Has any successfully applied a dynamic mapping template to the default type of an index? Take a look at the "dynamic_templates" section of this page:  http://www.elasticsearch.org/guide/reference/mapping/root-object-type.html (at the bottom).

Anyway, I am trying to implement dynamic templates in the elasticsearch PHP client and running into some problems. Here is my code:

$mapping = array(
"dynamic_templates" => array(
"template_ant" => array(
"match" => "*_i",
"mapping" => array(
"type" => "integer",
"index" => "not_analyzed",
"store" => "yes",
),
),
),
);

$type = $index->getType("_default_");
$type->setMapping($mapping);

But I am getting this exception:
Code: 0
Message: MapperParsingException[No type specified for property [dynamic_templates]]

Any help or guidance you can provide will be greatly appreciated!

Sky

SkyStebnicki

unread,
Apr 14, 2012, 11:20:57 AM4/14/12
to elastica-...@googlegroups.com
For more information, here is a gist that kimchy put up as an example of the request:

ruflin

unread,
Apr 15, 2012, 1:37:43 PM4/15/12
to elastica-...@googlegroups.com
I'm not sure, but the different could be on the following line:

            "dynamic_templates":[{

here we have an array inside an array. In your example, there is only one array.

SkyStebnicki

unread,
Apr 15, 2012, 10:02:23 PM4/15/12
to elastica-...@googlegroups.com
Hmm, putting it into a nested array returned this error:
0 - ElasticSearchException[java.util.ArrayList cannot be cast to java.util.Map]; nested: ClassCastException[java.util.ArrayList cannot be cast to java.util.Map];

$mapping = array(
	"dynamic_templates" => array(
		array(
			"template_ant"	=> array(
				"match" => "*_i",
				"mapping" => array(
					"type" => "integer",
					"index" => "not_analyzed",
					"store" => "yes",
				),
			),
		),
	),
);

Serdar Asgarov

unread,
Apr 16, 2012, 1:18:47 AM4/16/12
to elastica-...@googlegroups.com
May be i am wrong, but i think, if u use matching_type different from multi_field u need to use match_mapping_type

2012/4/16 SkyStebnicki <sky.st...@gmail.com>

SkyStebnicki

unread,
Apr 16, 2012, 12:08:27 PM4/16/12
to elastica-...@googlegroups.com
Alright, I got it working. The issue is the params have to be passed when the index is being created and I just did a raw request with $client->request("indexname"...) to create the index with the POSTed values for the dynamic templates.

Thanks for your help!

Sky


On Saturday, April 14, 2012 7:53:28 AM UTC-7, SkyStebnicki wrote:
On Saturday, April 14, 2012 7:53:28 AM UTC-7, SkyStebnicki wrote:

Nicolas Ruflin

unread,
Apr 16, 2012, 12:21:25 PM4/16/12
to elastica-...@googlegroups.com
Can you post the code that worked?

Jasper van Wanrooy

unread,
Mar 25, 2013, 12:10:20 PM3/25/13
to elastica-...@googlegroups.com
Yes, also interested in this!

Jasper van Wanrooy

unread,
Mar 25, 2013, 1:39:06 PM3/25/13
to elastica-...@googlegroups.com
Already made it work, gisted a demo here: https://gist.github.com/jappievw/5238757

ruflin

unread,
Mar 27, 2013, 9:03:38 AM3/27/13
to elastica-...@googlegroups.com
If you want to make me a favor: Create a test case out of this and also add it as an example to Elastica.io :-)

Jasper van Wanrooy

unread,
Apr 1, 2013, 5:25:07 PM4/1/13
to elastica-...@googlegroups.com
Sorry, it took a while to complete. Here you go: https://github.com/ruflin/Elastica/pull/358.
I couldn't find some documentation on how to create an example on Elastica.io. Can you point me in the right direction?

Thanks!

On 27 Mar 2013, at 14:03, ruflin <ruf...@gmail.com> wrote:

If you want to make me a favor: Create a test case out of this and also add it as an example to Elastica.io :-)

--
You received this message because you are subscribed to a topic in the Google Groups "Elastica - Elasticsearch PHP Client" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/elastica-php-client/rAB13i4gDBc/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to elastica-php-cl...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

ruflin

unread,
Apr 2, 2013, 8:13:07 AM4/2/13
to elastica-...@googlegroups.com
I see, I should add some documentation how to add documentation :-) I will create a README file soon ...

Add a .php page with the example here:


Add the link to the page here:

Reply all
Reply to author
Forward
0 new messages