OpenSearch查询报错:未使用的search_as_you_type字段触发fielddata不支持错误
OpenSearch查询未使用字段触发Fielddata错误问题
我针对salesorders索引执行以下查询:
{"query":{"bool":{"must":[{"range":{"created":{"gte":"2023-10-23T20:10:23","lte":"2023-12-23T20:10:23"}}},{"term":{"orderStatus.keyword":{"value":"ACC_ERROR"}}}]}}}
但通过OpenSearch .NET客户端返回错误:
Fielddata is not supported on field [orderReference] of type [search_as_you_type]
这个orderReference字段我根本没在查询里用到。如果直接通过OpenSearch API执行同一个查询,却能正常返回空结果:
{ "took": 7, "timed_out": false, "_shards": { "total": 0, "successful": 0, "skipped": 0, "failed": 0 }, "hits": { "total": { "value": 0, "relation": "eq" }, "max_score": null, "hits": [] } }
以下是我用OpenSearch.NET创建索引的代码:
var createIndexResponse = await _client.Indices.CreateAsync("salesorders", c => c .Map<SalesOrder>(m => m .AutoMap() .Properties(ps => ps .SearchAsYouType(s => s .Name(n => n.OrderReference) ) .SearchAsYouType(s => s .Name(n => n.CustomerName) ) .Nested<SalesOrderItem>(n => n .Name(nm => nm.LineItems) .AutoMap() // This will auto map the properties of SalesOrderItem .Properties(pps => pps .SearchAsYouType(s => s .Name(nn => nn.ActiveIngredients) ) .SearchAsYouType(s => s .Name(nn => nn.ArticleDescription) ) .SearchAsYouType(s => s .Name(nn => nn.Sku) ) .Number(n => n.Name(nn => nn.BackorderQuantity).Type(NumberType.Integer)) ) ) ) ) );
OpenSearch中的索引映射如下:
{ "salesorders": { "mappings": { "properties": { "created": { "type": "date" }, "customerName": { "type": "search_as_you_type", "doc_values": false, "max_shingle_size": 3 }, "customerNumber": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "customerReference": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "distributionChannel": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "division": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "erpOrderReference": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "invoiceCode": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "isFutureOrder": { "type": "boolean" }, "lineItems": { "type": "nested", "properties": { "activeIngredients": { "type": "search_as_you_type", "doc_values": false, "max_shingle_size": 3 }, "articleDescription": { "type": "search_as_you_type", "doc_values": false, "max_shingle_size": 3 }, "backorderQuantity": { "type": "integer" }, "discountPercentage": { "type": "double" }, "ean": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "expiryDate": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "incorrectOrderQuantityReceived": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "invoice": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "invoiceItem": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "invoiceNumber": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "isBackorder": { "type": "boolean" }, "itemCascaded": { "type": "boolean" }, "itemCategory": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "itemDiscountPercentage": { "type": "double" }, "lineId": { "type": "integer" }, "lineStatus": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "merchantCategory": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "netValue": { "type": "double" }, "orderQuantity": { "type": "integer" }, "prescriptionNumber": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "priceExclGst": { "type": "double" }, "rejectionDescription": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "rejectionReason": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "sasbReference": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "sku": { "type": "search_as_you_type", "doc_values": false, "max_shingle_size": 3 }, "substitutedArticle": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "subtotalExclGst": { "type": "double" }, "subtotalInclGst": { "type": "double" }, "suppliedQuantity": { "type": "integer" }, "userCancelled": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } } } }, "orderReference": { "type": "search_as_you_type", "doc_values": false, "max_shingle_size": 3 }, "orderSource": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "orderStatus": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "orderType": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "paymentReference": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "promotionId": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "returnReason": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "returnReasonDescription": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "salesOrganisation": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "sapCreatedDate": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "sapCreatedTime": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "sourceReturnReference": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "sraRequestComments": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "supplierCode": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "totalDiscountAmount": { "type": "double" }, "totalPrice": { "type": "double" }, "totalPriceExclGst": { "type": "double" }, "updated": { "type": "date" }, "userCreated": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } } } } } }
我搞不懂为什么没在查询里用到的orderReference字段会触发这个错误,这个字段只是被用作文档ID,按理说不该引发这类问题。
内容的提问来源于stack exchange,提问作者JamesMatson
相关产品推荐
相关产品推荐

