假设我有一个索引&我在这个声明中添加了一份文件:
POST /temp/item
{
"text": "dave@domain.com dave@do-main.com one,two three:four"
}
我想要一些查询语句来返回此文档,例如:
*@domain*
*@do-*
one,two
three:four
- >这实际上会产生错误每个都由类似于此的声明选择:
GET /temp/item/_search
{
"query": {
"bool": {
"must": [
{
"query_string": {
"query": "*@domain*",
"allow_leading_wildcard": "true",
"default_operator": "AND"
}
}
]
}
}
}
他们都没有回来。
我理解原因是分析器设置为standard
,它将文本按任何字边界分开。所以我认为我必须将分析仪更改为whitespace
,如下所示:
PUT /temp
{
"mappings": {
"item" : {
"properties" : {
"text" : {
"type" : "string",
"analyzer": "whitespace"
}
}
}
}
}
这样做并没有解决问题。该声明均未归还该文件。
答案 0 :(得分:0)
几乎您需要明确指定要匹配的query_string的“字段”。
可以使用default_field
或fields
选项指定案例
示例:
{
"query": {
"bool": {
"must": [
{
"query_string": {
"query": "*@domain*",
"fields": [
"text"
],
"allow_leading_wildcard": "true",
"default_operator": "AND"
}
}
]
}
}
}
如果未指定任何内容,query_string
将使用_all
字段。
2)three:four
需要用双引号括起来,否则会被解释为field:three
匹配query:four
例如:
{
"query": {
"bool": {
"must": [
{
"query_string": {
"query": "\"three:four\"",
"fields": [
"text"
],
"allow_leading_wildcard": "true",
"default_operator": "AND"
}
}
]
}
}
}