@stevebissett (Steve Bissett) posted a new topic, subject "Indexing same field twice is not working". It read:

   I have the following Ruby code to define my index:
    [code] 
         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"}
                                                           }
        
        
                                                       }
                                                   }
                                               }
                                           }
                                       }
        
    [/code]
    
    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:
    [code] 
        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"}}
                        }
                    }
                }
            }
        }
        
    [/code]
    
    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.

After which, @stevebissett (Steve Bissett) added

    This also shows what I'm trying to do in my searches, but it doesn't seem to work:  
    Elastic Blog – 23 Apr 14
    
    ### Multi-Field Search Just Got Better | Elastic
    
    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...

After which, @warkolm (Mark Walkom) added

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

So @system (system) replied

    


{'source': 'discourse', 'url': 'https://discuss.elastic.co/t/indexing-same-field-twice-is-not-working/44035', 'title': 'Indexing same field twice is not working', 'views': 1165, 'has_accepted_answer': False, 'word_count': 244, 'like_count': 0, 'reply_count': 1, 'participant_count': 2, 'posts': 4, 'tags': '', 'author': '@stevebissett (Steve Bissett)', 'participants': '@stevebissett (Steve Bissett), @warkolm (Mark Walkom), @system (system)', 'image_url': [None], 'created_at': '2016-03-10T13:08:01.084Z', 'last_posted_at': '2017-07-05T23:08:57.220Z'}