title: Elasticsearch Nest wildcard query with spaces
body: <p><strong>Short version:</strong></p>
  
  <p>I would like to write an elastic search query using Nest to get the full indexed items (<code>ContentIndexables</code> in my case as my custom type) which have been indexed. The query is subject to a term query of [some string] + * (i.e. String.StartsWith() where [some string] may or may not contain spaces.</p>
  
  <p>This is different to <code>CompletionSuggester</code> since I need to retrieve the full object and not string suggestions.</p>
  
  <p><strong>What I've tried so far:</strong></p>
  
  <p>When I query for a text without spaces, the desired output is returned using the code below. If my search term however contains spaces, it doesn't return the expected results.</p>
  
  <p>Here's how I search the fields:</p>
  
  <pre><code>var searchResults = _client.Search&lt;ContentIndexable&gt;(
              body =&gt;
              body
                  .Index(indexName)
                  .Query(
                      query =&gt;
                      query.QueryString(
                          qs =&gt; qs.
                                    OnFields(f =&gt; f.Title, f =&gt; f.TextContent)
                                    .Query(searchTerm + "*"))));
  </code></pre>
  
  <p>And this is a unit test that demonstrates how to reproduce the problem:</p>
  
  <pre><code>indexService.IndexUserItemsSync(testGuid, IndexType.submission, new ContentIndexable
          {
              ContentId = Guid.NewGuid(),
              TextContent = "Some description",
              Title = "title"
          });
  
          indexService.IndexUserItemsSync(testGuid, IndexType.submission, new ContentIndexable
          {
              ContentId = Guid.NewGuid(),
              TextContent = "Some description",
              Title = "title that is long"
          });
  
          indexService.IndexUserItemsSync(testGuid, IndexType.submission, new ContentIndexable
          {
              ContentId = Guid.NewGuid(),
              TextContent = "Some description",
              Title = "title that likes"
          });
  
          indexService.IndexUserItemsSync(testGuid, IndexType.submission, new ContentIndexable
          {
              ContentId = Guid.NewGuid(),
              TextContent = "Some description",
              Title = "titlethat"
          });
  
          var searchResult = indexService.SearchUserItems(testGuid, IndexType.submission, 10, "title");
          Assert.IsNotNull(searchResult);
  // this one works
          Assert.AreEqual(4, searchResult.Count());
  
          var searchResult2 = indexService.SearchUserItems(testGuid, IndexType.submission, 10, "title that");
          Assert.IsNotNull(searchResult2);
  // this one does not!!! searchREsult2.Count() evaluates to 0
          Assert.AreEqual(2, searchResult2.Count());
  </code></pre>
  
  <p>As you can see, then I enter "title that", the search comes back empty instead of the two rows I would expect to return.</p>
  
  <p><strong>Update:</strong>
  Some more information: 
  I create an index on my type ContentIndexable:</p>
  
  <pre><code>public class ContentIndexable : IIndexable
  {
      public Guid ContentId { get; set; }
      public string Title { get; set; }
      public string TextContent { get; set; }
  }
  </code></pre>
  
  <p>With this code: </p>
  
  <pre><code>_client.CreateIndex(
      indexName,
      descriptor =&gt;
      descriptor.AddMapping&lt;ContentIndexable&gt;(
          m =&gt; m.Properties(
              p =&gt; p.Completion(s =&gt; s
                                         .Name(n =&gt; n.Title)
                                         .IndexAnalyzer("standard")
                                         .SearchAnalyzer("standard")
                                         .MaxInputLength(30)
                                         .Payloads()
                                         .PreserveSeparators()
                                         .PreservePositionIncrements())
                       .Completion(s =&gt; s.Name(n =&gt; n.TextContent)
                                            .IndexAnalyzer("standard")
                                            .SearchAnalyzer("standard")
                                            .MaxInputLength(50)
                                            .Payloads()
                                            .PreserveSeparators()
                                            .PreservePositionIncrements())
                   )));
  </code></pre>
  
  <p>I even tried to escape the whitespace both when I index or when I query with <code>string.Replace(" ", @"\ ")</code> but that didn't help.</p>
  
  <p>Changing the search type to wild card didn't help either:</p>
  
  <pre><code>var searchResults = _client.Search&lt;ContentIndexable&gt;(
              body =&gt;
              body
                  .Index(indexName)
                  .Query(
                      query =&gt; query.Wildcard(qd =&gt; qd.OnField(f =&gt; f.Title).Value(searchTerm + "*"))));
  </code></pre>
  
  <p>Does anyone know what I'm doing wrong?</p>
  
  <p>Please note that my <code>CompletionSuggester</code> version works with spaces but unfortunately only returns strings. I need to get the <strong>complete item</strong> out in order to fetch the <code>ContentId</code>. MY CompletionSuggester implementation:</p>
  
  <pre><code>public IEnumerable&lt;string&gt; GetAutoCompleteSuggestions(Guid userId, IndexType indexType, int size, string searchTerm)
      {
          string indexName = getIndexName(indexType, userId);
  
          var result = _client.Search&lt;ContentIndexable&gt;(
              body =&gt; body.Index(indexName)
                          .SuggestCompletion("content-suggest" + Guid.NewGuid(),
                                             descriptor =&gt; descriptor
                                                               .OnField(t =&gt; t.Title)
                                                               .Text(searchTerm)
                                                               .Size(size)));
  
          if (result.Suggest == null)
          {
              return new List&lt;string&gt;();
          }
  
          return (from suggest in result.Suggest
                  from value in suggest.Value
                  from options in value.Options
                  select options.Text).Take(size);
      }
  </code></pre>
  
  <p>I know I can take the suggestions, get the full value out (which will result in the two items I'm expecting) and then do a full term match using my first method but that requires 2 separate calls into ElasticSearch (one for complete suggestor and the second one for the term query) but ideally I would like to do it without the round trip if possible.</p>
  
  <p>Many thanks in advance,</p>