dventi3
dventi3

Reputation: 991

Wildcard in elastichsearch with slash return zero entry

I am using elastichsearch 5 to store and search some documents. in my documents I have a field called URL like this:

{
    //... other fields
    "URL": "http://ip:8080/app/addItemToCart.html?workingItemId=X1"
}

I tried to use a query with wildcard because I would like to get all the documents with contain the word "addItemToCart" in the URL. This is my query:

GET myindex/_search
{
  "query" : {
    "wildcard" : { "URL" : "*addItemToCart*" }
  }
}

It returns zero documents but I I have documents in elasticsearch with that keyword.

This is my mapping for the index.

GET myindex/_mapping
{
  //.... other fields
    "URL": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      }
}

What is wrong?

Upvotes: 0

Views: 240

Answers (1)

glenacota
glenacota

Reputation: 2547

As stated in the documentation, a wildcard query

Matches documents that have fields matching a wildcard expression (not analyzed)

Therefore, your query should be:

GET myindex/_search
{
  "query" : {
    "wildcard" : { "URL.keyword" : "*addItemToCart*" }
  }
}

Upvotes: 1

Related Questions