Эластичный поиск: различные результаты для строки запроса при использовании полей - PullRequest
0 голосов
/ 11 октября 2018

У нас есть эластичный поиск 5.5.Мы используем nest для выполнения наших запросов через C #.

При выполнении следующего запроса:

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

Мы получаем желаемый результат: один результат с таким числом какидентификатор.

При использовании следующего запроса:

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

Мы не получаем результатов.

Значение, которое мы ищем, находится в поле searchIndentifier и имеет значение "1-00917751".

У нас есть специальный анализатор с именем "final"

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

Поле searchIndentifier не имеет пользовательского анализатораустановить на это.Мы попытались добавить в него токенайзер пробелов, но это не имело значения.

Другое поле с именем «searchObjectNo» работает, когда мы пытаемся найти значение «S328-25» с помощью запроса «S328».Эти поля абсолютно одинаковы.

Есть идеи?

Еще один вопрос.В первом запросе, когда мы ищем 1-00917751 (без кавычек), мы получаем много результатов.Но мы думаем, что это из-за ключевого слова токенизатор?

Спасибо

Schoof

Настройки индекса и сопоставления:

{
  "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 Ответ

0 голосов
/ 11 октября 2018

Ответ довольно прост: в вашем отображении ваше поле называется searchIndentifier, а в вашем запросе вы используете поле с именем searchIdentifier, которого не существует; -)

...