<commit_before>require File.expand_path(File.dirname(__FILE__) + '/spec_helper')

describe "bulk ops" do
  before(:all) do
    @index = 'first-' + Time.now.to_i.to_s
    @client = ElasticSearch.new('127.0.0.1:9200', :index => @index, :type => "tweet")
  end

  after(:all) do
    @client.delete_index(@index)
    sleep(1)
  end

  it "should index documents in bulk" do
    @client.bulk do |c|
      c.index({:foo => 'bar'}, :id => '1')
      c.index({:foo => 'baz'}, :id => '2')
    end
    @client.bulk do
      @client.index({:socks => 'stripey'}, :id => '3')
      @client.index({:socks => 'argyle'}, :id => '4')
    end
    @client.refresh

    @client.get("1").foo.should == "bar"
    @client.get("2").foo.should == "baz"
    @client.get("3").socks.should == "stripey"
    @client.get("4").socks.should == "argyle"
  end

  it "should take options"
  # check that url generated has options in query string
end<commit_msg>bulk options spec<commit_after>require File.expand_path(File.dirname(__FILE__) + '/spec_helper')

describe "bulk ops" do
  before(:all) do
    @index = 'first-' + Time.now.to_i.to_s
    @client = ElasticSearch.new('127.0.0.1:9200', :index => @index, :type => "tweet")
  end

  after(:all) do
    @client.delete_index(@index)
    sleep(1)
  end

  it "should index documents in bulk" do
    @client.bulk do |c|
      c.index({:foo => 'bar'}, :id => '1')
      c.index({:foo => 'baz'}, :id => '2')
    end
    @client.bulk do
      @client.index({:socks => 'stripey'}, :id => '3')
      @client.index({:socks => 'argyle'}, :id => '4')
    end
    @client.refresh

    @client.get("1").foo.should == "bar"
    @client.get("2").foo.should == "baz"
    @client.get("3").socks.should == "stripey"
    @client.get("4").socks.should == "argyle"
  end

  it "should take options" do
    @client.bulk do |c|
      c.index({:foo => 'bar'}, :id => '1', :_routing => '1', :_parent => '1')
      #TODO better way to test this?
      meta = c.instance_variable_get('@batch').detect { |b| b.has_key?(:index) }
      meta[:index].should include(:_routing => '1')
      meta[:index].should include(:_parent => '1')
    end
  end
end
{'fraction_non_alphanumeric': 0.20737972909855207, 'fraction_numerical': 0.02008407286314806, 'mean_word_length': 3.08, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3577689', 'n_tokens_mistral': 823, 'n_tokens_neox': 800, 'n_words': 178}