我们需要基于多个值来获取数据。因此,我尝试在modelNumber字段的弹性搜索中使用术语查询。但是它不能像expected.can那样工作,任何人都可以告诉我查询出了什么问题。
POST index_name/_Search
{
"query": {
"bool": {
"must": [
{
"terms": {
"modelNumber": [
"test 1234rthg-1234-1234512-2345",
"testMode11l-123-rtyu-xyz11"
]
}
},
{
"terms": {
"userId": [
"123",
"VALUE2"
]
}
}
]
}
}
}发布于 2021-01-13 21:19:42
Terms query返回在提供的字段中包含一个或多个精确术语的文档。
如果您尚未显式定义任何索引映射,则需要向modelNumber字段添加.keyword。这使用关键字分析器而不是标准分析器(请注意modelNumber后的".keyword“字段)。
{
"query": {
"bool": {
"must": [
{
"terms": {
"modelNumber.keyword": [ // note this
"test 1234rthg-1234-1234512-2345",
"testMode11l-123-rtyu-xyz11"
]
}
},
{
"terms": {
"userId": [
"123",
"VALUE2"
]
}
}
]
}
}
}或者需要修改modelNUmber字段的映射为-
{
"mappings": {
"properties": {
"modelNumber": {
"type": "keyword"
}
}
}
}https://stackoverflow.com/questions/65702543
复制相似问题