# Indexing same field twice is not working

**URL:** <https://discuss.elastic.co/t/indexing-same-field-twice-is-not-working/44035>\
**Category:** Elasticsearch\
**Created:** [March 10, 2016, 1:08pm UTC](https://discuss.elastic.co/t/indexing-same-field-twice-is-not-working/44035 "2016-03-10T13:08:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![stevebissett](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stevebissett/32/7983_2.png) [@stevebissett](https://discuss.elastic.co/u/stevebissett)\
**Post date:** [March 10, 2016, 1:08pm UTC](https://discuss.elastic.co/t/indexing-same-field-twice-is-not-working/44035/1 "2016-03-10T13:08:01Z")

</div>

I have the following Ruby code to define my index:

```
 self.client.indices.create index: self.index,
                               body: {
                                   settings: {
                                       analysis: {
                                           filter: {
                                               ngram: {
                                                   type: 'nGram',
                                                   min_gram: 2,
                                                   max_gram: 25
                                               }
                                           },
                                           analyzer: {
                                               ngram: {
                                                   tokenizer: 'whitespace',
                                                   filter: ['lowercase', 'stop', 'ngram'],
                                                   type: 'custom'
                                               },
                                               ngram_search: {
                                                   tokenizer: 'whitespace',
                                                   filter: ['lowercase', 'stop'],
                                                   type: 'custom'
                                               }
                                           }
                                       }
                                   },
                                   mappings: {
                                       search_variable: {
                                           properties: {
                                               "name" => {
                                                   "type" => "string",
                                                   "index" => "not_analyzed"
                                               },
                                               .... <some items removed here for brevity>,
                                               "node_id" => {
                                                   "type" => "integer",
                                                   "index" => "not_analyzed"
                                               },
                                               "search_text" => {
                                                   "type" => "multi_field",
                                                   "fields" => {
                                                       "search_text" => {"type" => "string",
                                                                         "analyzer" => "ngram",
                                                                         "search_analyzer" => "ngram_search"},
                                                       "whole_words" => {"type" => "string",
                                                                         "analyzer" => "ngram_search"}
                                                   }

                                               }
                                           }
                                       }
                                   }
                               }

```

This code is acknowledged and created successfully.  
I can confirm this with a get request to `localhost:9200/<index_name>` which shows the settings.

I would then have expected to be able to search `search_text` and `search_text.whole_words`, but it returns no hits for `search_text.whole_words`.

Here is my search query:

```
search_query = {
    index: index,
    body: {
        _source: {
            exclude: ["search_text", "survey_id", "ancestor_ids", "node_type"]
        },
        query: {
            :bool => {
                :filter => {
                    :term => {"survey_id" => 12}
                },
                :must => {
                    :match => {
                        #"search_text" => {"query" => "ford", "operator" => "and"},
                        "search_text.whole_words" => {"query" => "ford", "operator" => "and"}
                    },
                },
                :must_not => {
                    :match => {
                        "search_text" => {"query" => "", "operator" => "or"}}
                }
            }
        }
    }
}

```

It returns no results and I can't understand why.  
Basically, at the end, my requirement is that I want to be able to prioritise whole words.

---

<div class="post-metadata">

**Author:** ![stevebissett](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stevebissett/32/7983_2.png) [@stevebissett](https://discuss.elastic.co/u/stevebissett)\
**Post date:** [March 10, 2016, 1:19pm UTC](https://discuss.elastic.co/t/indexing-same-field-twice-is-not-working/44035/2 "2016-03-10T13:19:56Z")

</div>

This also shows what I'm trying to do in my searches, but it doesn't seem to work:

> **[Multi-Field Search Just Got Better
	  	 | Elastic](https://www.elastic.co/blog/multi-field-search-just-got-better)**
>
> The match query is the go-to query for matching on a single field. It understands the field mapping and uses the appropriate analyzer for the field, it can match any word or require all words (with op...

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [March 12, 2016, 2:26am UTC](https://discuss.elastic.co/t/indexing-same-field-twice-is-not-working/44035/3 "2016-03-12T02:26:30Z")

</div>

Once you have indexed data in, can you grab one of the docs to make sure that field has been populated?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 5, 2017, 11:08pm UTC](https://discuss.elastic.co/t/indexing-same-field-twice-is-not-working/44035/4 "2017-07-05T23:08:57Z")

</div>


