0

I have one field in which I am storing values like O5467508 (Starting with alphabet "O")

Below is my query.

{"from":0,"size":10,"query":{"bool":{"must":[{"match":{"field_LIST_105":{"query":"o5467508","type":"phrase_prefix"}}},{"bool":{"must":[{"match":{"RegionName":"Virginia"}}]}}]}}}

it is giving me correct result, But when i am searching for only numeric value "5467508", query result is empty.

Thanks in advance.

1 Answer 1

1

One of the possible solution that could help you, use word_delimiter filter, with the option preserve_original, which will save original token.

Something like this:

{
  "settings": {
    "analysis": {
      "analyzer": {
        "so_analyzer": {
          "type": "custom",
          "tokenizer": "keyword",
          "filter": [
            "lowercase",
            "my_word_delimiter"
          ]
        }
      },
      "filter": {
        "my_word_delimiter": {
          "type": "word_delimiter",
          "preserve_original": true
        }
      }
    }
  },
  "mappings": {
    "my_type": {
      "properties": {
        "field_LIST_105": {
          "type": "text",
          "analyzer": "so_analyzer"
        }
      }
    }
  }
}

I did a quick test of analysis, and this is the tokens that it give to me.

{
    "tokens": [
        {
            "token": "o5467508",
            "start_offset": 0,
            "end_offset": 8,
            "type": "word",
            "position": 0
        },
        {
            "token": "o",
            "start_offset": 0,
            "end_offset": 1,
            "type": "word",
            "position": 0
        },
        {
            "token": "5467508",
            "start_offset": 1,
            "end_offset": 8,
            "type": "word",
            "position": 1
        }
    ]
}

For more information - https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-word-delimiter-tokenfilter.html

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.