Adding keyword field to existing index text field for term agg / word autocomplete

Hi,
I want to be able to search two text fields on both full text search and keyword based for aggregation so that I can implement single word autocomplete, similar to the discussion here:

However when i created the index i set the fields i want to search to text fields (without the keyword field).

So i updated the mapping for these two fields as suggested in this link:

In my case I updated the abstract and the title properties.

The index currently was populated with 1.6 million documents, and this was done before i updated the mapping. After the update, my mapping is as follows:

{
  "library": {
    "mappings": {
      "paper": {
        "properties": {
          "abstract": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword"
              }
            }
          },
          "added_date": {
            "type": "integer"
          },
          "author_strings_json": {
            "type": "keyword"
          },
          "authors_json": {
            "properties": {
              "id": {
                "type": "long"
              },
              "name": {
                "type": "text",
                "fields": {
                  "keyword": {
                    "type": "keyword",
                    "ignore_above": 256
                  }
                }
              }
            }
          },
          "created_at": {
            "type": "integer"
          },
          "doi": {
            "type": "keyword"
          },
          "id": {
            "type": "long"
          },
          "image_url": {
            "type": "keyword"
          },
          "journal_id": {
            "type": "integer"
          },
          "mendeley_id": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "pdf_url": {
            "type": "keyword"
          },
          "processed": {
            "type": "boolean"
          },
          "published_date": {
            "type": "integer"
          },
          "s3_image_name": {
            "type": "keyword"
          },
          "suggest": {
            "type": "completion",
            "analyzer": "simple",
            "preserve_separators": true,
            "preserve_position_increments": true,
            "max_input_length": 50
          },
          "title": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword"
              }
            }
          },
          "unpaywall_urls": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "updated_at": {
            "type": "long"
          },
          "url": {
            "type": "keyword"
          },
          "valid": {
            "type": "boolean"
          }
        }
      }
    }
  }
}

However, when I use the following query:

GET library/_search?pretty
{
  "query": {
    "match_phrase_prefix": {
      "title.keyword": "arti"
    }
  },
  "size": 1, 
  "aggs": {
    "myagg": {
      "terms": {
        "field": "title.keyword",
        "include": "arti.*", 
        "size": 1
      }
    }
  }
}

I get no results (the buckets field is empty in the result)

Any idea what im doing wrong?

Thanks!
Justin

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.