我对弹性搜索很新。我有一个用例,我想在弹性搜索中搜索单个字段上列表的所有元素,如果存在任何一个,则检索文档。
例如:
List["Shruti","shreya","shreshtha"]
并在
上搜索“user.Name”表示返回所有具有这些名称的文件。
请你帮我解决一下这个问题。 在此先感谢。!
答案 0 :(得分:1)
这是一个简单的例子。
我创建了一个带有显式映射的简单索引,如下所示:
PUT /test_index
{
"mappings": {
"doc": {
"properties": {
"name": {
"type": "string"
}
}
}
}
}
然后使用bulk index操作添加了一些文档:
POST /test_index/doc/_bulk
{"index":{"_id":1}}
{"name":"Shruti"}
{"index":{"_id":2}}
{"name":"shreya"}
{"index":{"_id":3}}
{"name":"shreshtha"}
{"index":{"_id":4}}
{"name":"some other name"}
{"index":{"_id":5}}
{"name":"yet another"}
现在我可以查询几种不同的方式。像这样的默认match query将起作用:
POST /test_index/_search
{
"query": {
"match": {
"name": "Shruti shreya shreshtha"
}
}
}
您还可以使用terms filter,如下所示。但是在这里要小心。请注意,这些术语都是小写的。这是因为,由于我们没有在映射中指定分析器,因此使用了standard analyzer,它将令牌转换为小写。
POST /test_index/_search
{
"filter": {
"terms": {
"name": [
"shruti",
"shreya",
"shreshtha"
]
}
}
}
以下是我在示例中使用的代码:
http://sense.qbox.io/gist/e4f5a276aa59fb62e2e0207eb6199070014f0650