I actually wrote a blog post about this a while ago for Qbox , which you can find here: http://blog.qbox.io/multi-field-partial-word-autocomplete-in-elasticsearch-using-ngrams . (Unfortunately, some links to the message are broken, and at the moment they are not easy to fix, but I hope you get this idea.)
I will write you a message to find out the details, but here is some code that you can use for quick testing. Note that I use edge ngrams instead of full ngrams .
Also note, in particular, the use of the _ all field , and the match request operator .
Ok, so here is the mapping:
PUT /test_index { "settings": { "analysis": { "filter": { "edgeNGram_filter": { "type": "edgeNGram", "min_gram": 2, "max_gram": 20 } }, "analyzer": { "edgeNGram_analyzer": { "type": "custom", "tokenizer": "whitespace", "filter": [ "lowercase", "asciifolding", "edgeNGram_filter" ] } } } }, "mappings": { "doc": { "_all": { "enabled": true, "index_analyzer": "edgeNGram_analyzer", "search_analyzer": "standard" }, "properties": { "field1": { "type": "string", "include_in_all": true }, "field2": { "type": "string", "include_in_all": true } } } } }
Now add some documents:
POST /test_index/doc/_bulk {"index":{"_id":1}} {"field1":"purple duck","field2":"brown fox"} {"index":{"_id":2}} {"field1":"slow purple duck","field2":"quick brown fox"} {"index":{"_id":3}} {"field1":"red turtle","field2":"quick rabbit"}
And this query seems to illustrate what you want:
POST /test_index/_search { "query": { "match": { "_all": { "query": "purp fo slo", "operator": "and" } } } }
return:
{ "took": 5, "timed_out": false, "_shards": { "total": 5, "successful": 5, "failed": 0 }, "hits": { "total": 1, "max_score": 0.19930676, "hits": [ { "_index": "test_index", "_type": "doc", "_id": "2", "_score": 0.19930676, "_source": { "field1": "slow purple duck", "field2": "quick brown fox" } } ] } }
Here is the code I used to test it:
http://sense.qbox.io/gist/b87e426062f453d946d643c7fa3d5480cd8e26ec