0
votes

I have some documents in elasticsearch v5.2.2 that look like this:

{
  "took": 4,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "failed": 0
  },
  "hits": {
    "total": 3,
    "max_score": 1,
    "hits": [
      {
        "_index": "company",
        "_type": "external",
        "_id": "2",
        "_score": 1,
        "_source": {
          "name": "IBM",
          "bloomberg": "IBMB34:BZ"
        }
      },
      {
        "_index": "company",
        "_type": "external",
        "_id": "1",
        "_score": 1,
        "_source": {
          "name": "Apple",
          "bloomberg": "AAPL34:BZ"
        }
      },
      {
        "_index": "company",
        "_type": "external",
        "_id": "3",
        "_score": 1,
        "_source": {
          "name": "Microsoft",
          "bloomberg": "MSFT34:BZ"
        }
      }
    ]
  }
}

I would like to find all documents that contain a substring that possibly contains a special character (in my case ':').

{
    "query": {
        "wildcard" : { "bloomberg" : "*b34*" }
    }
}

Returns one result (as expected).

{
    "query": {
        "wildcard" : { "bloomberg" : "*b34:*" }
    }
}

Returns none. I have tried query_string and various other things but nothing seems to work.

1
What's the mapping of that field? - Andrei Stefan
Hi Andrei. I was using the standard analyzer and that was the issue. Changing the analyzer to the whitespace one fixed this for me (see my answer). - bm1729
Exactly ;-), thus my question about the mapping. - Andrei Stefan

1 Answers

1
votes

The problem is that the mapping I was using was just the out-of-the-box one. Changing the analyzer for the bloomberg filter to "whitespace" fixed this for me.

{
    "mappings": {
      "external" : {
        "properties" : {
          "name" : {
            "type" : "string",
            "analyzer": "standard",
            "search_analyzer": "standard"
          },
          "bloomberg" : {
            "type" : "string",
            "analyzer": "whitespace",
            "search_analyzer": "whitespace"
          }
        }
      }
    }
}