我是新的弹性,无法解决这个问题
我有2个请求:
1)curl -XGET 'host/process_test_1/1/_search?title:*New*'
它让我回头
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 116,
"max_score": 1.0,
"hits": [
{
"_index": "process_test_1",
"_type": "1",
"_id": "7118_folder_1",
"_score": 1.0,
"_source": {
"obj_type": "folder",
"obj_id": 7118,
"title": "sadasd"
}
},
{
"_index": "process_test_1",
"_type": "1",
"_id": "6780_folder_1",
"_score": 1.0,
"_source": {
"obj_type": "folder",
"obj_id": 6780,
"title": "New Object"
}
}
}
]
}
}
为什么它会给我一个标题为“sadasd”的对象?
和第二次请求
`curl -XGET 'host/process_test_1/1/_search' -d '{"query":{"match":{"text":{"query":"*New*","operator":"and"}}}}`'
它返回
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 0,
"max_score": null,
"hits": [
]
}
}
如果我真的有一个匹配的元素(实际上我有超过50个元素具有这样的名称和不同的ID),为什么它会返回我nothins
答案 0 :(得分:2)
首先,您的第一个查询缺少参数名称q=
curl -XGET 'host/process_test_1/1/_search?q=title:*New*'
^
|
this is missing
其次,match
查询并不将*
字符解释为通配符,因此如果您想要使用DSL进行上述第一个查询的等效查询,则需要使用改为query_string
查询:
curl -XGET 'host/process_test_1/1/_search' -d '{
"query": {
"query_string": {
"query": "*New*",
"default_field": "text"
}
}
}'