Elasticsearch ngram on entire document
<p>I currently build a contact search for a php and mysql based system. All the data that should be searchable gets synced into elasticsearch and the documents look like this:</p>

<pre><code>{

    "_index": "persons",
    "_type": "person",
    "_id": "705",
    "_version": 1,
    "_score": 1,
    "_source": {
        "firstname": "Jaida",
        "lastname": "Walter",
        "id": 705,
        "title": "Miss",
        "nickname": "",
        "gender": "female",
        "birthday": "1992-12-29",
        "companies": [
            "Mann, Bailey and Hills"
            ,
            "West PLC"
            ,
            "Keebler-Howe"
            ,
            "Hills LLC"
            ,
            "Toy, Gusikowski and Mohr"
            ,
            "Halvorson-Fadel"
            ,
            "Ratke PLC"
            ,
            "Turcotte-Franecki"
            ,
            "Bernier-Flatley"
            ,
            "Wisozk, Bernhard and Osinski"
        ],
        "emailAddresses": [ ],
        "addresses": [
            "Doe Street 47, 07691 JaneVille"
            ,
            "Doe Street 78, 84294 JaneVille"
            ,
            "Doe Street 37, 31698 JohnVille"
            ,
            "Doe Street 54, 62462 JaneVille"
            ,
            "Doe Street 31, 37672 JohnVille"
        ],
        "phoneNumbers": [ ]
    }

}
</code></pre>

<p>Now I would like to allow the user to search on all of these fields and also use partial words in his/her query. I reasearched on this topic and found the ngram filter. I tried to implement everything with the documentation and some blog posts. I currently use the following index settings:</p>

<pre><code>  $params = [
        'index' =&gt; SearchPerson::getIndex(),
        'body' =&gt; [
            'settings' =&gt; [
                "analysis" =&gt; [
                    "analyzer" =&gt; [
                        "ngram_analyzer" =&gt; [
                            "type" =&gt; "custom",
                            "tokenizer" =&gt; "whitespace",
                            "filter" =&gt; ["asciifolding", "lowercase", "ngram"]
                        ],
                        "whitespace_analyzer" =&gt; [
                            "type" =&gt; "custom",
                            "tokenizer" =&gt; "whitespace",
                            "filter" =&gt; [
                                "lowercase",
                                "asciifolding"
                            ]
                        ]
                    ],
                    "filter" =&gt; [
                        "ngram" =&gt; [
                            "type" =&gt; "ngram",
                            "min_gram" =&gt; 2,
                            "max_gram" =&gt; 20,
                            "token_chars" =&gt; [
                                "letter",
                                "digit",
                                "punctuation",
                                "symbol"
                            ]
                        ]
                    ]
                ]
            ],
            'mapping' =&gt; [
                'person' =&gt; [
                    '_all' =&gt; [
                        'analyzer' =&gt; 'ngram_analyzer',
                        'search_analyzer' =&gt; 'whitespace_analyzer'
                    ],
                    'properties' =&gt; [
                        'firstname' =&gt; [
                            'analyzer' =&gt; 'ngram_analyzer',
                            'search_analyzer' =&gt; 'whitespace_analyzer'
                        ]
                    ]
                ]
            ]
        ]
    ];
</code></pre>

<p>Saddly when I query the index I allways get the same document in return which is not the one I intended to find.</p>

<p><strong>Edit 1:</strong> </p>

<p>This is my query:</p>

<pre><code>{
  "size": 10,
  "query": {
    "match": {
      "_all": {
        "query": "Terill",
        "minimum_should_match": "100%"
      }
    }
  }
}
</code></pre>

<p>I also tried to query different fields (firstname for example) and removed the "minimum_should_match".</p>

<p>I allwas get the following document as result:</p>

<pre><code>{

    "_index": "persons",
    "_type": "person",
    "_id": "701",
    "_version": 1,
    "_score": 1,
    "_source": {
        "firstname": "Austen",
        "lastname": "Braun",
        "id": 701,
        "title": "Mr.",
        "nickname": "",
        "gender": "male",
        "birthday": "2008-05-15",
        "companies": [
            "Abshire, Fadel and Kiehn"
            ,
            "Wolf-Bogan"
            ,
            "Kohler-Langosh"
            ,
            "Howe, Skiles and Boyer"
            ,
            "Rippin, Batz and Ondricka"
            ,
            "Gislason-Kirlin"
        ],
        "emailAddresses": [ ],
        "addresses": [
            "Doe Street 68, 28012 JaneVille"
            ,
            "Doe Street 12, 78992 JohnVille"
            ,
            "Doe Street 23, 75805 JaneVille"
            ,
            "Doe Street 95, 46066 JohnVille"
            ,
            "Doe Street 72, 28754 JohnVille"
        ],
        "phoneNumbers": [ ]
    }

}
</code></pre>

<p>But with the above search query I am looking for this one:</p>

<pre><code>{

    "_index": "persons",
    "_type": "person",
    "_id": "712",
    "_version": 1,
    "_score": 1,
    "_source": {
        "firstname": "Terrill",
        "lastname": "Parker",
        "id": 712,
        "title": "Mr.",
        "nickname": "",
        "gender": "male",
        "birthday": "1970-07-12",
        "companies": [
            "Abshire, Fadel and Kiehn"
            ,
            "Zemlak Ltd"
            ,
            "McDermott, Schuppe and Mayer"
            ,
            "Ledner, Rosenbaum and Maggio"
            ,
            "Schoen PLC"
            ,
            "Hills LLC"
            ,
            "Tromp, Abernathy and Kuvalis"
            ,
            "Toy, Gusikowski and Mohr"
            ,
            "Hyatt-Flatley"
            ,
            "Rippin, Batz and Ondricka"
            ,
            "Jenkins-Corwin"
            ,
            "Ratke PLC"
        ],
        "emailAddresses": [
            "john66@doe.com"
            ,
            "pdoe@doe.info"
        ],
        "addresses": [
            "Doe Street 31, 35283 JaneVille"
            ,
            "Doe Street 78, 46721 JohnVille"
            ,
            "Doe Street 48, 39953 JohnVille"
            ,
            "Doe Street 24, 31388 JohnVille"
            ,
            "Doe Street 84, 35932 JohnVille"
        ],
        "phoneNumbers": [
            "747-058-484"
            ,
            "027-478-036"
        ]
    }

}
</code></pre>

<p><strong>Edit 2:</strong></p>

<p>I found <a href="https://www.elastic.co/guide/en/elasticsearch/reference/2.3/breaking_20_mapping_changes.html#_analyzer_mappings" rel="nofollow">this document</a> stating that there were changes in the analyzer mappings. I updated my mappings but still get the same results. Also I created a <a href="https://gist.github.com/Mawalu/9dee10a97fcfdec133729737b27d034b" rel="nofollow">gist</a> for the problem.</p>