title: How to search with regex for fields containing whitespace-separated segments in Elasticsearch
body: <p>I have a document which contains a field called info_list which is basically a string with space separated 9 segments.</p>
  <p>Mapping of the field is</p>
  <pre><code>&quot;info_list&quot;: {
          &quot;type&quot;: &quot;text&quot;,
          &quot;fields&quot;: {
            &quot;keyword&quot;: {
              &quot;type&quot;: &quot;keyword&quot;,
              &quot;ignore_above&quot;: 256
            }
          }
        }
  </code></pre>
  <p>And the source document looks like</p>
  <pre><code>&quot;_source&quot;: {
        &quot;id&quot;: &quot;1234&quot;,
        &quot;date&quot;: &quot;1614556800000&quot;,
        &quot;info_list&quot;: [
          &quot;1234 2D 5678 8765 5678 1111 2222 3333 1&quot;
        ]
      }
  </code></pre>
  <p>The info list basically consists of 9 segments. For sake of question we can say that a,b,c,d,e,f,g,h,i are those 9 segments.</p>
  <pre><code>info_list = a+ ' ' + b+ ' ' + c +' ' + d+ ' ' e + ' ' + f + ' ' + g + ' ' + h + ' ' + i
  </code></pre>
  <p>Now suppose I want to search for c with value of 5678, the current implementation uses match_phrase query something like this</p>
  <pre><code>GET test/_search
  {
    &quot;query&quot;: {
      &quot;match_phrase&quot;: {
        &quot;info_list&quot;: &quot;5678&quot;
      }
    }
  }
  </code></pre>
  <p>The issue with above approach is that ,even though I wanted search result having c = 5678, now if any segment in info_list string has 5678 it will match that, resulting in wrong search result.</p>
  <p>I tried using regex query something like</p>
  <pre><code>GET /test/_search
  {
    &quot;query&quot; : {
      &quot;query_string&quot; : 
      { &quot;fields&quot; : [&quot;info_list&quot;],
        &quot;query&quot; : &quot;.* .* 5678 .*&quot;
        
      }
      
    }
  }
  </code></pre>
  <p>But this doesn't seem to work.Should I change the mapping of the field ? Any help or suggestions would be appreciated, since I am new to Elastic search.</p>