我正在使用 elastic4s 来索引和搜索 ES 中的数据。我存储的部分文档包含一个我需要搜索的 url 字段(整个 url)。当我搜索包含 url 字段的文档并获得 0 个结果时,就会出现问题。
出于此搜索的目的,我在将数据插入索引之前定义了一个映射:
client.execute {
create index <my_index> mappings {
<my_type> as {
"url" typed StringType analyzer NotAnalyzed
}
}
}
我正在插入数据:
client.execute { index into <my_index> -> <my_type> fields (
"url" -> "http://sample.com"
)
}.await
我搜索文件:
val filter =
"""
|{
| "filtered" : {
| "query" : {
| "match_all" : {}
| },
| "filter" : {
| "bool" : {
| "should" : [
| { "bool" : {
| "must" : [
| { "term" : { "url" : "http://sample.com" } }
| ]
| } }
| ]
| }
| }
| }
|}
""".stripMargin
client.execute { search in <my_index> -> <my_type> rawQuery { filter } }.await
执行此查询后,我得到 0 个结果。我究竟做错了什么?
谢谢!