# Weird Search behavior for a beginner

**URL:** <https://discuss.elastic.co/t/weird-search-behavior-for-a-beginner/152729>\
**Category:** Elasticsearch\
**Created:** [October 16, 2018, 11:52pm UTC](https://discuss.elastic.co/t/weird-search-behavior-for-a-beginner/152729 "2018-10-16T23:52:29Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![saz](https://avatars.discourse-cdn.com/v4/letter/s/ecb155/32.png) [@saz](https://discuss.elastic.co/u/saz)\
**Post date:** [October 16, 2018, 11:52pm UTC](https://discuss.elastic.co/t/weird-search-behavior-for-a-beginner/152729/1 "2018-10-16T23:52:30Z")

</div>

Hi Team,  
Just starting out with project on ElasticSearch. Just landed on a solution which actually  
worked for a problem but I am frustrated how that it actually works ??!!! Would like to  
understand what's going on behind the scene for indexing the data.

Consider the test data

```
DELETE vinsearch

PUT vinsearch
{
  "mappings": {
    "vins" : {
      "properties": {
        "vin": {
          "type": "text"
        }
      }
    }
  }
}

PUT vinsearch/vins/1
{
  "vin" : "4JGDA5HB8HA89799"
}

PUT vinsearch/vins/2
{
  "vin" : "4JGDA5HB8HA89222"
}

PUT vinsearch/vins/3
{
  "vin" : "4JGDA5HB8HA89333"
}

```

Now , When I search on vin with following query, it does not work

```
POST vinsearch/_search
{
  "from" : 0,
  "size" : 10,
  "query" : {
    "bool" : {
      "must" : [
        {
          "match" : {
            "vin" : {
              "query" : "4jgda5hb8ha89799,4JGDA5HB8HA89222,4JGDA5HB8HA89333"
            }
          }
        }
      ],
      "boost" : 1.0
    }
  }
} 

```

But somehow if i would add an empty ,, between vins (See below) , the search result would come back...  
WHY IT IS THAT ??? Can someone enlighten me please ?

```
POST vinsearch/_search
{
  "from" : 0,
  "size" : 10,
  "query" : {
    "bool" : {
      "must" : [
        {
          "match" : {
            "vin" : {
              "query" : "4jgda5hb8ha89799,,4JGDA5HB8HA89222,,4JGDA5HB8HA89333"
            }
          }
        }
      ],
      "boost" : 1.0
    }
  }
}
```

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [October 17, 2018, 4:23am UTC](https://discuss.elastic.co/t/weird-search-behavior-for-a-beginner/152729/2 "2018-10-17T04:23:54Z")

</div>

Try analyze API to understand what's happening behind the scene. That should help a lot.

---

<div class="post-metadata">

**Author:** ![saz](https://avatars.discourse-cdn.com/v4/letter/s/ecb155/32.png) [@saz](https://discuss.elastic.co/u/saz)\
**Post date:** [October 17, 2018, 2:56pm UTC](https://discuss.elastic.co/t/weird-search-behavior-for-a-beginner/152729/3 "2018-10-17T14:56:10Z")

</div>

Thanks David.  
I have tried this already but not sure if there is anything useful to figure out.  
For example for the \_analyse API request,

```
GET _analyze
{
  "explain": true, 
  "analyzer": "standard", 
  "text" : "4JGDA5HB8HA89799"
}

```

I see the below response. Do you see anything useful to the problem i described?

```
{
  "detail": {
    "custom_analyzer": false,
    "analyzer": {
      "name": "standard",
      "tokens": [
        {
          "token": "4jgda5hb8ha89799",
          "start_offset": 0,
          "end_offset": 16,
          "type": "<ALPHANUM>",
          "position": 0,
          "bytes": "[34 6a 67 64 61 35 68 62 38 68 61 38 39 37 39 39]",
          "positionLength": 1,
          "termFrequency": 1
        }
      ]
    }
  }
} 

```

Why would searching for multiple vins in query string will not work without  
a dummy colon (,,) ?  
"query" : "4JGDA5HB8HA89222,4JGDA5HB8HA89333" -\> Fails  
"query" : "4JGDA5HB8HA89222,,4JGDA5HB8HA89333" -\> Works

---

<div class="post-metadata">

**Author:** ![saz](https://avatars.discourse-cdn.com/v4/letter/s/ecb155/32.png) [@saz](https://discuss.elastic.co/u/saz)\
**Post date:** [October 18, 2018, 2:38pm UTC](https://discuss.elastic.co/t/weird-search-behavior-for-a-beginner/152729/4 "2018-10-18T14:38:39Z")

</div>

@dadoonet any thoughts??

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [November 8, 2018, 7:04pm UTC](https://discuss.elastic.co/t/weird-search-behavior-for-a-beginner/152729/5 "2018-11-08T19:04:04Z")

</div>

Here is how your query is transformed:

```auto
GET _analyze
{
  "analyzer": "standard", 
  "text" : "4JGDA5HB8HA89222,4JGDA5HB8HA89333"
}

```

Gives:

```auto
{
  "tokens": [
    {
      "token": "4jgda5hb8ha89222,4jgda5hb8ha89333",
      "start_offset": 0,
      "end_offset": 33,
      "type": "<ALPHANUM>",
      "position": 0
    }
  ]
}

```

Which obviously does not match `4jgda5hb8ha89222` or `4jgda5hb8ha89333`.

And:

```auto
GET _analyze
{
  "analyzer": "standard", 
  "text" : "4JGDA5HB8HA89222,,4JGDA5HB8HA89333"
}

```

gives:

```auto
{
  "tokens": [
    {
      "token": "4jgda5hb8ha89222",
      "start_offset": 0,
      "end_offset": 16,
      "type": "<ALPHANUM>",
      "position": 0
    },
    {
      "token": "4jgda5hb8ha89333",
      "start_offset": 18,
      "end_offset": 34,
      "type": "<ALPHANUM>",
      "position": 1
    }
  ]
}

```

Which obviously matches might match on `4jgda5hb8ha89333` or `4jgda5hb8ha89222`.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [December 6, 2018, 7:04pm UTC](https://discuss.elastic.co/t/weird-search-behavior-for-a-beginner/152729/6 "2018-12-06T19:04:08Z")

</div>

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