0
votes

We have an elastic search 5.5 setup. We use nest to perform our queries through C#.

When executing the following query:

{
  "query": {
    "bool": {
      "must": [
        {
          "query_string": {
            "query": "00917751"
          }
        }
      ]
    }
  }
}

We get the desired result: one result with that the number as identifier.

When using the following query:

{
  "query": {
    "bool": {
      "must": [
        {
          "query_string": {
            "query": "00917751",
            "fields": [
              "searchReference",
              "searchIdentifier",
              "searchObjectNo",
              "searchBrand",
              "searchExtSerNo"
            ]
          }
        }
      ]
    }
  }
}

We get no results.

The value we are searching for is in the field searchIndentifier, and has the value "1-00917751".

We have a custom analyzer called "final"

.Custom("final", cu => cu .Tokenizer("keyword").Filters(new List() { "lowercase" }))

The field searchIndentifier has no custom analyzer set on it. We tried adding the whitespace tokenizer in it but that made no difference.

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.

Any ideas here?

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?

Thank you

Schoof

Index settings and mappings:

{
  "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"
        }
      }
    }
  }
}
1
It would help to see your index settings and mappings. Please update your question with what you get from curl -XGET localhost:9200/yourindexVal
@Val: We are hosting elastic search on a windows environment, I don't think curl exists on Windows?Schoof
Powershell ;-) Otherwise from Kibana GET you-indexVal
@Val Added, thank you! :)Schoof
@Schoof for curl, you can use Windows Subsystem for Linux (WSL). If you want a similar experience in PowerShell, take a look at gist.github.com/russcam/7fbdbaa37e3dcb3fd3ee0aa54af3708cRuss Cam

1 Answers

1
votes

The answer is pretty simple: in your mapping your field is named searchIndentifier and in your query you're using a field called searchIdentifier which doesn't exist ;-)