Which mapping data type should be user for particulartText

Hi,

Current Index Mapping is-

 "question_prompt": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },

Actually, I am working on a Question dataset where multiple questions are mapped in the question prompt field.

question prompt field consist question such as
For Ex-"1a. How GOOD are you at collecting or managing information or data?"

Questions starting with 1a,2a,2b, and so on are not present in the question_prompt.keyword field.

It May be due to the integer value present in the field and the text field is not working due to that.

Can someone tell me how to set correct mapping for such field which will show all questions starting from integer value in question_prompt.keyword field.

Lets start with the mapping options

keyword [1]:

keyword , which is used for structured content such as IDs, email addresses, hostnames, status codes, zip codes, or tags.

text [2]:

A field to index full-text values, such as the body of an email or the description of a product. These fields are analyzed , that is they are passed through an analyzer to convert the string into a list of individual terms before being indexed.

  1. Keyword type family | Elasticsearch Guide [8.11] | Elastic
  2. Text type family | Elasticsearch Guide [8.11] | Elastic

Probably the easiest query is:

curl -X GET "localhost:9200/_search?pretty" -H 'Content-Type: application/json' -d'
{
  "query": {
    "match": {
      "question_prompt": {
        "query": "1a"
      }
    }
  }
}
'

Note we're using the text field here. It analyzes the field and lets us perform full text search on the field.

Keyword fields are generally used for exact matches and aggregations. You may be able to perform a wildcard lookup by searching for 1a* with question_prompt.keyword.

Do either of these options work for you? If we want to get into specifics and best practices, we have to move this thread over to the Elasticsearch forum.

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