shanta mohapatra
shanta mohapatra

Reputation: 21

prefixQuery in Elastic search not working

{
  "from": 0,
  "size": 100,
  "timeout": "10m",
  "query": {
    "bool": {
      "must": [
        {
          "bool": {
            "must": [
              {
                "bool": {
                  "filter": [
                    {
                      "bool": {
                        "must": [
                          {
                            "term": {
                              "input.custom_attrs.index": {
                                "value": "1",
                                "boost": 1
                              }
                            }
                          }
                        ]
                      }
                    },
                    {
                      "bool": {
                        "must": [
                          {
                            "prefix": {
                              "input.custom_attrs.value": {
                                "value": "An*",
                                "boost": 1
                              }
                            }
                          }
                        ]
                      }
                    }
                  ]
                }
              }
            ]
          }
        }
      ]
    }
  }
}

Explanation - I want to search the field with "An" as prefix . Also i am sure that there is data with value "Annual" and "Annual Fund" ,which should appears in all match search . But these records are not appearing with prefix query as given above.I tried with regexp query and wildcard query too .But they are also not working .Please give your valuable suggestions how to make the query working.

Upvotes: 2

Views: 878

Answers (1)

Amit
Amit

Reputation: 32376

Possible causes why it's not working

look like while indexing data you used the default mapping or text field, which uses the default standard analyzer which converts the generated tokens to lowercase.

While prefix queries are not analyzed and search term doesn't go through any analyzer and will not be lowercased.

In your case, you are searching for An, note capital A, while for Annual and Annual fund, tokens would be annual and annual and fund, hence its not matching.

Solution:

Please use an as your prefix query and you should get your search results.

Upvotes: 4

Related Questions