Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Implement put mapping API. #194

Closed
wants to merge 1 commit into from

4 participants

@dylanahsmith

http://www.elasticsearch.org/guide/reference/api/admin-indices-put-mapping.html

The mapping for all types can be set in the index creation request, but
the mapping for a single type must be updated per put mapping request.

@dylanahsmith dylanahsmith Implement put mapping API.
http://www.elasticsearch.org/guide/reference/api/admin-indices-put-mapping.html

The mapping for all types can be set in the index creation request, but
the mapping for a single type must be updated per put mapping request.
58e4f6d
@karmi
Owner

Hello Dylan, thanks, sorry for such embarrasing delay.

I hate to be the asshole who asks for more tests all the time, but I think an integration test would be warranted?

Also what about mapping conflicts? What about the ignore_conflicts option?

@jfredett

Pretty sure this would fix index creation w/ bonsai (with a little bit of supporting code) -- I'll see if I can write up some integration tests when I get it all working w/ bonsai.

Open source at work!

@nz
nz commented

+1; this is relevant to my interests. Updating mapping at the index level won't be an issue with Bonsai for much longer, but it always helps to be specific.

@jfredett feel free to drop me a line if you need any support for this stuff on our end over at Bonsai

@karmi
Owner

@dylanahsmith Let's close this until we have a more complete iplementation with handling or ignoring conflicts, displaying diffs, etc etc?

@karmi karmi referenced this pull request
Closed

Support for PUT mappings #358

@karmi karmi referenced this pull request from a commit
@karmi Refactored the "Put Mapping" API support
* Cleaned up and simplified code
* Made the return values more compatible with the rest of the API (return `false` for failures, users should check `index.response`)
* Removed `put_mapping!`
* Amended, completed and polished tests
* Updated documentation

Related: #194, #490, #520, #645
8fc5060
@MrRuru MrRuru referenced this pull request from a commit in jobteaser/tire
@karmi Refactored the "Put Mapping" API support
* Cleaned up and simplified code
* Made the return values more compatible with the rest of the API (return `false` for failures, users should check `index.response`)
* Removed `put_mapping!`
* Amended, completed and polished tests
* Updated documentation

Related: #194, #490, #520, #645
26f467b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 6, 2012
  1. @dylanahsmith

    Implement put mapping API.

    dylanahsmith authored
    http://www.elasticsearch.org/guide/reference/api/admin-indices-put-mapping.html
    
    The mapping for all types can be set in the index creation request, but
    the mapping for a single type must be updated per put mapping request.
This page is out of date. Refresh to see the latest.
Showing with 24 additions and 0 deletions.
  1. +14 −0 lib/tire/index.rb
  2. +10 −0 test/unit/index_test.rb
View
14 lib/tire/index.rb
@@ -41,6 +41,20 @@ def mapping
MultiJson.decode(@response.body)[@name]
end
+ def update_mapping(mapping)
+ mapping.each do |type, value|
+ url, body = "#{Configuration.url}/#{@name}/#{type}/_mapping", MultiJson.encode(type => value)
+ begin
+ @response = Configuration.client.put url, body
+ raise RuntimeError, "#{@response.code} > #{@response.body}" if @response.failure?
+ ensure
+ curl = %Q|curl -X PUT "#{url}" -d '#{body}'|
+ logged('MAPPING', curl)
+ end
+ end
+ true
+ end
+
def store(*args)
document, options = args
type = get_type_from_document(document)
View
10 test/unit/index_test.rb
@@ -132,6 +132,16 @@ class IndexTest < Test::Unit::TestCase
assert_equal 2.0, @index.mapping['article']['properties']['title']['boost']
end
+ should "update the mapping" do
+ Configuration.client.expects(:put).twice.returns(mock_response('{"ok":true,"acknowledged":true}'))
+
+ mapping = {
+ :article => { :properties => { :title => { :type => 'string', :boost => 2.0 } } },
+ :user => { :properties => { :name => { :type => 'string' } } },
+ }
+ assert @index.update_mapping mapping
+ end
+
end
context "when storing" do
Something went wrong with that request. Please try again.