title: Understanding the "left_index" and "right_index" arguments in pandas merge
body: <p>I am really struggling to understand the "left_index" and "right_index" arguments in pandas.merge. I read the documentation, searched around, experimented with various setting and tried to understand but I am still confused. Consider this example:</p>
  
  <pre><code>left = pd.DataFrame({'key1': ['K0', 'K0', 'K1', 'K2'], 
                   'key2': ['K0', 'K1', 'K0', 'K1'],
                   'A': ['A0', 'A1', 'A2', 'A3'],
                   'B': ['B0', 'B1', 'B2', 'B3']})
  
  right = pd.DataFrame({'key1': ['K0', 'K1', 'K1', 'K2'],
                        'key2': ['K0', 'K0', 'K0', 'K0'],
                        'C': ['C0', 'C1', 'C2', 'C3'],
                        'D': ['D0', 'D1', 'D2', 'D3'],
                        'E': [1,2,3,4]})
  </code></pre>
  
  <p>Now, when I run the following command:</p>
  
  <pre><code>pd.merge(left, right, left_on=['key2', 'key1'], right_on=['key1', 'key2'], how='outer', indicator=True, left_index=True)
  </code></pre>
  
  <p>I get:</p>
  
  <pre><code>  key1_x key2_x    A    B key1_y key2_y    C    D    E      _merge
  0     K0     K0   A0   B0     K0     K0   C0   D0  1.0        both
  1     K0     K1   A1   B1     K1     K0   C1   D1  2.0        both
  2     K0     K1   A1   B1     K1     K0   C2   D2  3.0        both
  3     K1     K0   A2   B2    NaN    NaN  NaN  NaN  NaN   left_only
  3     K2     K1   A3   B3    NaN    NaN  NaN  NaN  NaN   left_only
  3    NaN    NaN  NaN  NaN     K2     K0   C3   D3  4.0  right_only
  </code></pre>
  
  <p>However, running the same with <code>right_index=True</code> gives an error. Same if I introduce both. More interestingly, running the following merge gives a very unexpected result</p>
  
  <pre><code>pd.merge(left, right,  on=['key1', 'key2'],how='outer', validate = 'one_to_many', indicator=True, left_index = True, right_index = True)
  </code></pre>
  
  <p>Result is:</p>
  
  <pre><code>  key1 key2   A   B   C   D  E _merge
  0   K0   K0  A0  B0  C0  D0  1   both
  1   K0   K1  A1  B1  C1  D1  2   both
  2   K1   K0  A2  B2  C2  D2  3   both
  3   K2   K1  A3  B3  C3  D3  4   both
  </code></pre>
  
  <p>As you can see, all information for right frame for <code>key1</code> and <code>key2</code> is completely lost.</p>
  
  <p>Please help me understand the purpose and function of these arguments. Thank you.</p>