rubyelasticsearchelasticsearch-ruby

Analyzing the same search field twice returns 0 results on subfield in ElasticSearch


I have a field called search_text which is a full text search field.

I am using ngrams to index this field, I wanted to add a new sub-field search_text.words that will index this on whole words.

I tried to implement this, but querying the search_text.words always returns 0 hits.

I am creating it like this:

  "search_text" => {
      "type" => "string",
      "analyzer" => "ngram",
      "search_analyzer" => "ngram_search",
      "fields" => {
          "words" => {"type" => "string",
                      "analyzer" => "ngram_search"}
      }
  }

I have a full demonstration here:

https://www.dropbox.com/s/wwxm3qe0oxc2z5y/Slimmed%20ElasticSearch%20Text%20%281%29.html?dl=0


Solution

  • Looking at your dropbox file, I think the issue is that the mapping type is called search_variable while in your bulk query you are using the mapping type test_type.

    Hence the mapping will never be applied.

    If you change your bulk query to this, it will work

    bulk_insert_items = items_to_insert.flat_map do |item|
          [
            {index: {_index: 'test_index', _type: 'search_variable'}},
            item
          ]
    end