title: Elastic Search: Different results for query string when using fields
body: <p>We have an elastic search 5.5 setup. We use nest to perform our queries through C#.</p>
  
  <p>When executing the following query:</p>
  
  <blockquote>
  <pre><code>{
    "query": {
      "bool": {
        "must": [
          {
            "query_string": {
              "query": "00917751"
            }
          }
        ]
      }
    }
  }
  </code></pre>
  </blockquote>
  
  <p>We get the desired result: one result with that the number as identifier.</p>
  
  <p>When using the following query:</p>
  
  <blockquote>
  <pre><code>{
    "query": {
      "bool": {
        "must": [
          {
            "query_string": {
              "query": "00917751",
              "fields": [
                "searchReference",
                "searchIdentifier",
                "searchObjectNo",
                "searchBrand",
                "searchExtSerNo"
              ]
            }
          }
        ]
      }
    }
  }
  </code></pre>
  </blockquote>
  
  <p>We get no results. </p>
  
  <p>The value we are searching for is in the field searchIndentifier, and has the value "1-00917751".</p>
  
  <p>We have a custom analyzer called "final"</p>
  
  <blockquote>
    <p>.Custom("final", cu => cu
                                    .Tokenizer("keyword").Filters(new List() { "lowercase" }))</p>
  </blockquote>
  
  <p>The field searchIndentifier has no custom analyzer set on it. We tried adding the whitespace tokenizer in it but that made no difference.</p>
  
  <p>Another field called "searchObjectNo" does work, when we try to search for the value "S328-25" with the query "S328". These fields are exactly the same.</p>
  
  <p>Any ideas here?</p>
  
  <p>Another question. In the first query, when we search for 1-00917751 (without the quotes) we get a lot of results. But we think that is because of the keyword tokenizer? </p>
  
  <p>Thank you</p>
  
  <p>Schoof</p>
  
  <p>Index settings and mappings:</p>
  
  <pre><code>{
    "inventoryitems": {
      "aliases": {},
      "mappings": {
        "inventoryobject": {
          "properties": {
            "articleGroups": {
              "type": "nested",
              "properties": {
                "id": {
                  "type": "long"
                }
              }
            },
            "articleId": {
              "type": "long"
            },
            "articleNumber": {
              "type": "text",
              "boost": 1.5,
              "analyzer": "final"
            },
            "brand": {
              "type": "text",
              "analyzer": "final"
            },
            "catalogues": {
              "type": "nested",
              "properties": {
                "articleGroupId": {
                  "type": "long"
                },
                "articleGroupName": {
                  "type": "text",
                  "analyzer": "final",
                  "fielddata": true
                },
                "id": {
                  "type": "long"
                },
                "name": {
                  "type": "text",
                  "analyzer": "final",
                  "fielddata": true
                }
              }
            },
            "details": {
              "type": "nested",
              "properties": {
                "actualState": {
                  "type": "double"
                },
                "allocation": {
                  "type": "text",
                  "analyzer": "final",
                  "fielddata": true
                },
                "available": {
                  "type": "double"
                },
                "batch": {
                  "type": "text",
                  "analyzer": "final"
                },
                "calibrationDate": {
                  "type": "date"
                },
                "expected": {
                  "type": "double"
                },
                "externalSerialNumber": {
                  "type": "text",
                  "fields": {
                    "keyword": {
                      "type": "keyword",
                      "ignore_above": 256
                    }
                  }
                },
                "id": {
                  "type": "text",
                  "fields": {
                    "keyword": {
                      "type": "keyword",
                      "ignore_above": 256
                    }
                  }
                },
                "inReturn": {
                  "type": "double"
                },
                "inventory": {
                  "type": "double"
                },
                "isInMobileCarrier": {
                  "type": "boolean"
                },
                "locationDetail": {
                  "type": "text",
                  "fields": {
                    "keyword": {
                      "type": "keyword",
                      "ignore_above": 256
                    }
                  }
                },
                "locationId": {
                  "type": "long"
                },
                "locationName": {
                  "type": "text",
                  "analyzer": "final",
                  "fielddata": true
                },
                "locationType": {
                  "type": "text",
                  "analyzer": "final",
                  "fielddata": true
                },
                "lotId": {
                  "type": "long"
                },
                "mobileCarrierCode": {
                  "type": "text",
                  "analyzer": "final",
                  "fielddata": true
                },
                "mobileCarrierId": {
                  "type": "long"
                },
                "ownerCode": {
                  "type": "text",
                  "analyzer": "final"
                },
                "requested": {
                  "type": "double"
                },
                "reserved": {
                  "type": "double"
                },
                "storeLocationId": {
                  "type": "long"
                },
                "thicknessCode": {
                  "type": "text",
                  "analyzer": "final"
                },
                "weldedMark": {
                  "type": "text",
                  "analyzer": "final"
                }
              }
            },
            "docNo": {
              "type": "long"
            },
            "hasStock": {
              "type": "boolean"
            },
            "id": {
              "type": "text",
              "fields": {
                "keyword": {
                  "type": "keyword",
                  "ignore_above": 256
                }
              }
            },
            "identifier": {
              "type": "text",
              "boost": 1.5,
              "analyzer": "final"
            },
            "inventoryItemType": {
              "properties": {
                "name": {
                  "type": "text",
                  "analyzer": "final",
                  "fielddata": true
                }
              }
            },
            "mobileCarrierId": {
              "type": "long"
            },
            "name": {
              "type": "text",
              "boost": 1.5,
              "analyzer": "final"
            },
            "objectNumber": {
              "type": "text",
              "boost": 1.5,
              "analyzer": "final"
            },
            "quantity": {
              "type": "double"
            },
            "reference": {
              "type": "text",
              "boost": 1.5,
              "analyzer": "final"
            },
            "searchBrand": {
              "type": "text",
              "fields": {
                "keyword": {
                  "type": "keyword",
                  "ignore_above": 256
                }
              }
            },
            "searchExtSerNo": {
              "type": "text",
              "fields": {
                "keyword": {
                  "type": "keyword",
                  "ignore_above": 256
                }
              }
            },
            "searchIndentifier": {
              "type": "text",
              "fields": {
                "keyword": {
                  "type": "keyword",
                  "ignore_above": 256
                }
              }
            },
            "searchName": {
              "type": "text",
              "fields": {
                "keyword": {
                  "type": "keyword",
                  "ignore_above": 256
                }
              }
            },
            "searchObjectNo": {
              "type": "text",
              "fields": {
                "keyword": {
                  "type": "keyword",
                  "ignore_above": 256
                }
              }
            },
            "searchReference": {
              "type": "text",
              "fields": {
                "keyword": {
                  "type": "keyword",
                  "ignore_above": 256
                }
              }
            },
            "sortNumber": {
              "type": "long"
            },
            "stockUnit": {
              "type": "text",
              "boost": 1.5,
              "analyzer": "final"
            }
          }
        }
      },
      "settings": {
        "index": {
          "number_of_shards": "3",
          "provided_name": "inventoryitems",
          "creation_date": "1539253308319",
          "analysis": {
            "analyzer": {
              "final": {
                "filter": [
                  "lowercase"
                ],
                "type": "custom",
                "tokenizer": "keyword"
              }
            }
          },
          "number_of_replicas": "1",
          "uuid": "Kb5KuYEiR5GQqgBPVYjJfA",
          "version": {
            "created": "5050299"
          }
        }
      }
    }
  }
  </code></pre>