# Discrepancy (bug or misunderstanding) in how simple\_query\_string handles queries?

**URL:** https://discuss.elastic.co/t/discrepancy-bug-or-misunderstanding-in-how-simple-query-string-handles-queries/299351
**Category:** Elasticsearch
**Created:** [March 10, 2022, 3:34pm UTC](https://discuss.elastic.co/t/discrepancy-bug-or-misunderstanding-in-how-simple-query-string-handles-queries/299351 "2022-03-10T15:34:57Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![ndtreviv](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ndtreviv/32/22494_2.png) [@ndtreviv](https://discuss.elastic.co/u/ndtreviv)
#### Post date: [March 10, 2022, 3:34pm UTC](https://discuss.elastic.co/t/discrepancy-bug-or-misunderstanding-in-how-simple-query-string-handles-queries/299351/1 "2022-03-10T15:34:57Z")

</div>

I have a field, let's call it `MyField` mapped as a `keyword` type.  
If I search using `simple_query_string`, like so:

```auto
GET /my-index/_search
{
  "from": 0,
  "size": 1000,
  "query": {
    "bool": {
      "filter": [
        {
          "simple_query_string": {
            "query": "l120 2007:09:11 98c57u495891",
            "fields": [
              "MyField^1.0"
            ],
            "flags": -1,
            "default_operator": "and",
            "analyze_wildcard": true,
            "auto_generate_synonyms_phrase_query": true,
            "fuzzy_prefix_length": 0,
            "fuzzy_max_expansions": 50,
            "fuzzy_transpositions": true,
            "boost": 1
          }
        }
      ],
      "adjust_pure_negative": true,
      "boost": 1
    }
  },
  "explain": false,
  "_source": {
    "includes": [],
    "excludes": []
  },
  "track_total_hits": 10000
}

```

returns no results. But if I search specifically using bool filter:

```auto
GET /index/_search
{
    "from": 0,
    "size": 1000,
    "query": {
        "bool": {
            "filter": [
                {
                        "term": {
                            "MyField": "l120 2007:09:11 98c57u495891"
                        }
                }
            ],
            "adjust_pure_negative": true,
            "boost": 1.0
        }
    },
    "explain": false,
    "_source": {
        "includes": [],
        "excludes": []
    },
    "track_total_hits": 10000
}

```

then I do get results as expected.

Why doesn't the `simple_query_string` search type give me results?

(es version 7.8.0)  
Thanks for any help offered!

---

<div class="post-metadata">

### Author: ![casterQ](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/casterq/32/93257_2.png) [@casterQ](https://discuss.elastic.co/u/casterQ)
#### Post date: [March 11, 2022, 3:00am UTC](https://discuss.elastic.co/t/discrepancy-bug-or-misunderstanding-in-how-simple-query-string-handles-queries/299351/2 "2022-03-11T03:00:33Z")

</div>

this is different between `term-level` query and `full text` query：  
`term-level` query is for ` keyword` type and `full text` query is for `text` type.  
`simple_query_string` is one for `full text` query and you can try as follow, it means `match_phrase` by using `\"something\"`

```auto
 "simple_query_string": {
            "query": "\"l120 2007:09:11 98c57u495891\"",
            "fields": [
              "MyField^1.0"
            ],

```

---

<div class="post-metadata">

### Author: ![ndtreviv](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ndtreviv/32/22494_2.png) [@ndtreviv](https://discuss.elastic.co/u/ndtreviv)
#### Post date: [March 14, 2022, 9:52am UTC](https://discuss.elastic.co/t/discrepancy-bug-or-misunderstanding-in-how-simple-query-string-handles-queries/299351/3 "2022-03-14T09:52:22Z")

</div>

Thanks for the explanation, @casterQ, unfortunately the suggestion didn't work.

I'm guessing that if I really want to search across all fields in a consistent manner than I can't mix and match my field types between text and term.

If I want to enjoy the benefits of both, I'll need to change my mapping to:

```auto
"MyField": {
    "type": "text",
    "properties": {
        "keyword" : {
            "type": "keyword"
        }
    }
}

```

and either target `MyField` or `MyField.keyword`?

Is there no way to target keyword-type fields with a `simple_query_string` type field?

---

<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: [April 11, 2022, 9:52am UTC](https://discuss.elastic.co/t/discrepancy-bug-or-misunderstanding-in-how-simple-query-string-handles-queries/299351/4 "2022-04-11T09:52:25Z")

</div>

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