title: ElasticSearch.NET NEST search<T> url
body: <p>My correct index path is <code>POST: /foo/_search</code> but below code hits <code>POST: /foo/bar/_search</code>. </p>
  
  <pre><code>var node = new Uri("http://elasticsearch-server.com:9200");
  var settings = new ConnectionSettings(node);
  settings.DefaultIndex("foo");
  var client = new ElasticClient(settings);
  var response = client.Search&lt;Bar&gt;(s =&gt; s
  .Query(q =&gt; q.Term(o =&gt; o.userName, "test"))
  );
  
  // POCO for response fields
  public class Bar
  {
      public int userId { get; set; }
      public string userName { get; set; }
      public DateTime createdTime { get; set; }
  }
  </code></pre>
  
  <p>Above code <code>response</code> returns below message;</p>
  
  <blockquote>
    <p>Valid NEST response built from a successful low level call on POST: /foo/bar/_search</p>
  </blockquote>
  
  <p>How can I set search path correctly?</p>
  
  <p><strong>Trial 1</strong></p>
  
  <p>When I omitted <code>settings.DefaultIndex("foo");</code> line, it throws <code>ArgumentException</code> as below, but when I set <code>DefaultIndex()</code>, <code>Search&lt;T&gt;</code> uses <code>T</code> name as a second path.</p>
  
  <blockquote>
    <p>ArgumentException: Index name is null for the given type and no default index is set. Map an index name using ConnectionSettings.MapDefaultTypeIndices() or set a default index using ConnectionSettings.DefaultIndex().</p>
  </blockquote>
  
  <p><strong>Trial 2</strong>
  Refer to the <a href="https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/index-name-inference.html#_mapping_an_index_name_for_pocos_2" rel="noreferrer">documentation</a>, </p>
  
  <pre><code>var settings = new ConnectionSettings(node)
  .MapDefaultTypeIndices(m =&gt; m.Add(typeof(Bar), "foo"));
  </code></pre>
  
  <p>Above code returns same result in response.</p>
  
  <blockquote>
    <p>Valid NEST response built from a successful low level call on POST: /foo/bar/_search</p>
  </blockquote>