Skip to content

Commit

Permalink
add query to setMapping in Type Class (#1216) (#1312)
Browse files Browse the repository at this point in the history
  • Loading branch information
p365labs authored and ruflin committed May 19, 2017
1 parent a941cc3 commit 436dd0e
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -14,6 +14,7 @@ All notable changes to this project will be documented in this file based on the

- Parameter `filter_path` for response filtering (e.g. `$index->search($query, ['filter_path' => 'hits.hits._source'])`)
- Add support for Health parameters for Cluster\Health endpoint (new prop : delayed_unassigned_shards, number_of_pending_tasks, number_of_in_flight_fetch, task_max_waiting_in_queue_millis, active_shards_percent_as_number)
- Add support for querystring in Type. this allow to use `update_all_types` in type mapping in order to resolve conflicts between fields in different types. [Conflicts between fields in different types](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-put-mapping.html#merging-conflicts)

### Improvements

Expand Down
5 changes: 3 additions & 2 deletions lib/Elastica/Type.php
Expand Up @@ -292,15 +292,16 @@ public function getName()
* Sets value type mapping for this type.
*
* @param \Elastica\Type\Mapping|array $mapping Elastica\Type\MappingType object or property array with all mappings
* @param array $query querystring when put mapping (for example update_all_types)
*
* @return \Elastica\Response
*/
public function setMapping($mapping)
public function setMapping($mapping, array $query = [])
{
$mapping = Mapping::create($mapping);
$mapping->setType($this);

return $mapping->send();
return $mapping->send($query);
}

/**
Expand Down
46 changes: 46 additions & 0 deletions test/Elastica/TypeTest.php
Expand Up @@ -990,4 +990,50 @@ public function testRequestEndpoint()
$mapping['mappings']
);
}

/**
* @group functional
*
* @expectedException \Elastica\Exception\ResponseException
*/
public function testExceptionMappingOnFieldsWithSameName()
{
$index = $this->_createIndex();
$type1 = new Type($index, 'foo');
$type2 = new Type($index, 'bar');

$mapping = new Mapping(null, $expect = [
'text' => ['type' => 'text', 'analyzer' => 'standard'],
]);
$type1->setMapping($mapping);
$type2->setMapping($mapping);

$mapping2 = new Mapping($type1, $expect = [
'text' => ['type' => 'text', 'analyzer' => 'standard', 'search_analyzer' => 'whitespace'],
]);
$type1->setMapping($mapping2);
}

/**
* @group functional
*
*/
public function testMappingOnFieldsWithSameName()
{
$index = $this->_createIndex();
$type1 = new Type($index, 'foo');
$type2 = new Type($index, 'bar');

$mapping = new Mapping(null, $expect = [
'text' => ['type' => 'text', 'analyzer' => 'standard'],
]);
$type1->setMapping($mapping);
$type2->setMapping($mapping);

$mapping2 = new Mapping($type1, $expect = [
'text' => ['type' => 'text', 'analyzer' => 'standard', 'search_analyzer' => 'whitespace'],
]);
$type1->setMapping($mapping2, ['update_all_types' => 'update_all_types']);
$this->assertTrue(true);
}
}

0 comments on commit 436dd0e

Please sign in to comment.