我正撞着桌子试图解决这个问题。当在名字为“Willa”的记录上搜索字段customer.FirstName时,我得到的结果为“W”,“WI”,“WIL”,“WILLA”,但不是“WILL”。例如,以下工作:
curl -XPOST "http://.../someindex/_search?pretty=true" -d'
{
"query": {
"query_string": {
"query": "will",
"fields": [
"FirstName"
]
}
},
"script_fields": {
"terms": {
"script": "doc[field].values",
"params": {
"field": "customer.FirstName"
}
}
}
}'
以上的结果是:
{
"took": 0,
"timed_out": false,
"_shards": {
"total": 2,
"successful": 2,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 1.8629173,
"hits": [
{
"_index": "someindex",
"_type": "customer",
"_id": "585B1F34-5822-4859-802D-E2218D1E6FCF",
"_score": 1.8629173,
"fields": {
"terms": [
"w",
"wi",
"wil",
"will",
"willa"
]
}
}
]
}
}
但是,以下内容不会返回任何结果:
curl -XPOST "http://.../someindex/_search?pretty=true" -d'
{
"query": {
"query_string": {
"query": "willa",
"fields": [
"FirstName"
]
}
},
"script_fields": {
"terms": {
"script": "doc[field].values",
"params": {
"field": "customer.FirstName"
}
}
}
}'
这就是customer.FirstName Willa的索引编制方式:
GET /devpac2/_analyze?field=customer.FirstName&text=Willa
{
"tokens": [
{
"token": "w",
"start_offset": 0,
"end_offset": 1,
"type": "word",
"position": 1
},
{
"token": "wi",
"start_offset": 0,
"end_offset": 2,
"type": "word",
"position": 2
},
{
"token": "wil",
"start_offset": 0,
"end_offset": 3,
"type": "word",
"position": 3
},
{
"token": "will",
"start_offset": 0,
"end_offset": 4,
"type": "word",
"position": 4
},
{
"token": "willa",
"start_offset": 0,
"end_offset": 5,
"type": "word",
"position": 5
}
]
}
我做错了什么?