title: Full text Search with Multiple index in Elastic Search using NEST C#
body: <p>I'm trying to search Multiple indexes Elasticsearch with NEST Client, I just follow the below link<br>
  [stackover post ]<a href="https://stackoverflow.com/questions/47836986/how-to-search-inside-multiple-indices-using-nest-elasticsearch">How to search inside multiple indices using Nest ElasticSearch?</a>
  the only difference was my indexes are already existed but nothing returns </p>
  
  <p>Sample code : </p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using Elasticsearch.Net;
  using Nest;
  
  namespace ElasticSearchDemo
  {
  
  
      public class ExceptionData
      {
          public bool HasException { get; set; }
          public string ExceptionMessage { get; set; }
      }
      public class ElasticSearchResponse : ExceptionData
      {
          public ISearchResponse&lt;dynamic&gt; elasticSearchResponse { get; set; }
      }
  
      public class ComponentTypES
      {
          public string ComponentID { get; set; }
          public string Componentname { get; set; }
          public string Summary { get; set; }
      }
  
      public class ProjectTypES
      {
          public string ProjectID { get; set; }
          public string Projectname { get; set; }
          public string Summary { get; set; }
          public string Description { get; set; }
      }
      class Program
      {
          static void Main(string[] args)
          {
              // calling the function
              var response = GetAllSearchResults("test", 0, 10);
  
  
  
          }
  
          public static ElasticClient GetElasticSearchCommonSearch()
          {
              ElasticClient elasticClient = null;
              try
              {
                  const string strElasticSearchURL = "http://localhost:9200/";
                  const string componentIndex = "componenttypeindex";
                  const string projectIndex = "projecttypeindex";
  
                  if (!string.IsNullOrEmpty(strElasticSearchURL))
                  {
                      ConnectionSettings connectionSettings = new ConnectionSettings(new Uri(strElasticSearchURL))
                          .DefaultIndex(componentIndex)
                          .DefaultMappingFor&lt;ComponentTypES&gt;(i =&gt; i.IndexName(componentIndex).TypeName("Componenttype"))
                          .DefaultMappingFor&lt;ProjectTypES&gt;(j =&gt; j.IndexName(projectIndex).TypeName("Projecttype"))
  
                          .DisableDirectStreaming()
                          .PrettyJson()
                                  .OnRequestCompleted(callDetails =&gt;
                                  {
                                      if (callDetails.RequestBodyInBytes != null)
                                      {
                                          Console.WriteLine(
                                              $"{callDetails.HttpMethod} {callDetails.Uri} \n" +
                                              $"{Encoding.UTF8.GetString(callDetails.RequestBodyInBytes)}");
                                      }
                                      else
                                      {
                                          Console.WriteLine($"{callDetails.HttpMethod} {callDetails.Uri}");
                                      }
  
                                      Console.WriteLine();
  
                                      if (callDetails.ResponseBodyInBytes != null)
                                      {
                                          Console.WriteLine($"Status: {callDetails.HttpStatusCode}\n" +
                                                   $"{Encoding.UTF8.GetString(callDetails.ResponseBodyInBytes)}\n" +
                                                   $"{new string('-', 30)}\n");
                                      }
                                      else
                                      {
                                          Console.WriteLine($"Status: {callDetails.HttpStatusCode}\n" +
                                                   $"{new string('-', 30)}\n");
                                      }
                                  }
                          );
  
                      elasticClient = new ElasticClient(connectionSettings);
                  }
  
              }
              catch (Exception ex)
              {
                  throw new Exception(ex.Message + "  ConnectionObject for : Common Search");
              }
  
              return elasticClient;
          }
  
          public static ElasticSearchResponse GetAllSearchResults(string query = "test", int
                                                page = 1, int pagesize = 10)
          {
              ElasticSearchResponse combinedResponse = new   ElasticSearchResponse();
  
              try
              {
                  ElasticClient elasticClient =  GetElasticSearchCommonSearch();
  
                  var clusterHealth = elasticClient.ClusterHealth();
                  if (clusterHealth.IsValid &amp;&amp; string.Compare(clusterHealth.Status.ToString(), "red", true) != 0 &amp;&amp; clusterHealth.ServerError == null)
                  {
                      string Componentindex = "componenttypeindex";
                      string Projectindex =  "projecttypeindex";
  
                      var indices = Indices.Index(typeof(ComponentTypES)).And(typeof(ProjectTypES));
  
                      //elasticClient.Refresh(indices);
  
                      //TODO : Development time coding 
  
                      if (null != (indices))
                      {
                          var indexExists = elasticClient.IndexExists(Indices.Index(Componentindex));
                          var projectExists = elasticClient.IndexExists(Indices.Index(Projectindex));
  
                          if (indexExists.Exists &amp;&amp; indexExists.IsValid &amp;&amp; projectExists.Exists &amp;&amp; projectExists.IsValid)
                          {
  
  
                              //full text example 1
  
                              combinedResponse.elasticSearchResponse = elasticClient.Search&lt;object&gt;(s =&gt; s
                               .Index(indices)
                               .Type(Types.Type(typeof(ComponentTypES), typeof(ProjectTypES)))
                               .Query(q =&gt; (q
                               .MultiMatch(m =&gt; m
                                .Fields(f =&gt; f
                                        .Field(Infer.Field&lt;ComponentTypES&gt;(ff =&gt; ff.Componentname))
                                        .Field(Infer.Field&lt;ComponentTypES&gt;(ff =&gt; ff.Summary, 1.1))
                                          )
                                .Operator(Operator.Or)
                                .Query(query)
                                           ) &amp;&amp; +q
                               .Term("_index", Componentindex)) || (q
                               .MultiMatch(m =&gt; m
                               .Fields(f =&gt; f
                                           .Field(Infer.Field&lt;ProjectTypES&gt;(ff =&gt; ff.Projectname))
                                           .Field(Infer.Field&lt;ProjectTypES&gt;(ff =&gt; ff.Summary, 0.3))
                                )
                                .Operator(Operator.Or)
                                .Query(query)
                                 ) &amp;&amp; +q
                                   .Term("_index", Projectindex))
                                ).From(page - 1)
                                .Size(pagesize)
  
                                 );
  
  
                              //free text example 2
                              combinedResponse.elasticSearchResponse = elasticClient.Search&lt;object&gt;(s =&gt; s
                                                               .Index(indices)
                                                               .Type(Types.Type(typeof(ComponentTypES), typeof(ProjectTypES)))
                                                               .Query(q =&gt; (q
                                                                   .MatchPhrase(m =&gt; m
                                                                           .Field(Infer.Field&lt;ComponentTypES&gt;(ff =&gt; ff.Componentname))
                                                                           .Query(query)
                                                                   ) &amp;&amp; +q
                                                                   .Term("_index", Componentindex)) || (q
                                                                   .MatchPhrase(m =&gt; m
                                                                       .Field(Infer.Field&lt;ProjectTypES&gt;(ff =&gt; ff.Projectname))
                                                                       .Query(query)
                                                                       )
                                                                   ) &amp;&amp; +q
                                                                   .Term("_index", Projectindex)
                                                               ).From(page - 1)
                                                               .Size(pagesize)
                                                          );
  
  
  
                          }
                          else
                          {
                              combinedResponse.HasException = true;
                              combinedResponse.ExceptionMessage = "Index Not Found";
                          }
                      }
                      else
                      {
                          combinedResponse.HasException = true;
                          combinedResponse.ExceptionMessage = "Index Not Found In Config File";
                      }
                  }
                  else
                  {
                      combinedResponse.HasException = true;
                      combinedResponse.ExceptionMessage = "Error on connecting with ElasticSearch";
                  }
              }
              catch (Exception ex)
              {
                  combinedResponse.HasException = true;
                  combinedResponse.ExceptionMessage = ex.Message;
                  return combinedResponse;
              }
  
              return combinedResponse;
          }
  
  
      }
  }
  </code></pre>
  
  <p>Elastic table schema:</p>
  
  <pre><code>PUT componenttypeindex
  {
    "mappings": {
      "Componenttype":{
        "properties":{
          "ComponentID":{"type":"text"},
          "Componentname":{"type":"text"},
          "Summary":{"type":"text"}
             }
          }
      }
  }
  
  PUT projecttypeindex
  {
    "mappings": {
      "Projecttype":{
        "properties":{
          "ProjectID":{"type":"text"},
          "Projectname":{"type":"text"},
          "Summary":{"type":"text"},
           "Description":{"type":"text"}
                  }
              }
           }
  }
  </code></pre>
  
  <p>it should return query matched items, but nothing returns 
  sorry for my ugly code formatting I tried but the new editor won't change anything </p>
  
  <p>UPDATE :
  i've updated the Index values in the query as suggested by @RussCam but still no expected results , and also when expands the response objects and ran the URI parameter in directly in Browser it has all the results something weird not sure why this not shown in response count </p>
  
  <p>Valid NEST response built from a successful low level call on POST: /componenttypeindex%2Cprojecttypeindex/Componenttype%2CProjecttype/_search?typed_keys=true</p>
  
  <h1>Audit trail of this API call:</h1>
  
  <ul>
  <li>[1] Healthy Response: Node: <a href="http://localhost:9200/" rel="nofollow noreferrer">http://localhost:9200/</a> Took: 00:00:00.0620000
  
  <h1>Request:</h1></li>
  </ul>
  
  <p>
  
  <p>URI =  "<a href="http://localhost:9200/componenttypeindex%2Cprojecttypeindex/Componenttype%2CProjecttype/_search?typed_keys=true" rel="nofollow noreferrer">http://localhost:9200/componenttypeindex%2Cprojecttypeindex/Componenttype%2CProjecttype/_search?typed_keys=true</a>"</p>
  
  <p>My POCO Classes:</p>
  
  <pre><code>public class ComponentTypES
  {
      public string ComponentID { get; set; }
      public string Componentname { get; set; }
      public string Summary { get; set; }
  
  }  
  
  public class ProjectTypES
  {
  
      public string ProjectID { get; set; }
      public string Projectname { get; set; }
      public string Summary { get; set; }
      public string Description { get; set; } 
  }
  </code></pre>
  
  <p>sample Data :</p>
  
  <pre><code>PUT componenttypeindex/Componenttype/5342e739-1635-4021-baf2-55e25b95b8ec
  {
      "ComponentID":"5342e739-1635-4021-baf2-55e25b95b8ec",
      "Componentname":"TestComponent1",
      "Summary":"this is summary of test component1"
  }
  
  PUT componenttypeindex/Componenttype/90781386-8065-11e9-bc42-526af7764f64
  {    
      "ComponentID":"90781386-8065-11e9-bc42-526af7764f64",
      "Componentname":"TestComponent2",
      "Summary":"this is summary of test component3"  
  }
  PUT componenttypeindex/Componenttype/19871386-8065-11e9-bc42-526af7764f64
  {
      "ComponentID":"19871386-8065-11e9-bc42-526af7764f64",
      "Componentname":"some xyz component test",
      "Summary":"this is summary test of test xyz"
  }
  
  
  PUT projecttypeindex/Projecttype/5342e739-2019-4021-baf2-55e25b95b8ec
  {
          "ProjectID":"5342e739-2019-4021-baf2-55e25b95b8ec",
          "Projectname":"Test Project1",
          "Summary":"summary of Test Project1",
          "Description":"Description of TestProject1"
  }
  
  PUT projecttypeindex/Projecttype/5342f739-2019-4021-baf2-55e25b95b8ba
  {
          "ProjectID":"5342f739-2019-4021-baf2-55e25b95b8ba",
          "Projectname":"Test Project2",
          "Summary":"summary of Test Project2",
          "Description":"Description of TestProject1"
  }
  
  PUT projecttypeindex/Projecttype/6342f739-2020-4021-baf2-55e25b95b8ac
  {
          "ProjectID":"6342f739-2020-4021-baf2-55e25b95b8ac",
          "Projectname":"some PQRS project",
          "Summary":"summary of PQRS Project",
          "Description":"Description of PQORS Project1"
  }
  </code></pre>