我有一堆带有数组字段的文档,如下所示:
{ "feed_uids": ["math.CO", "cs.IT"] }
Run Code Online (Sandbox Code Playgroud)
我想找到包含这些值的某些子集的所有文档,即将它们视为标记.文档让我相信术语过滤器应该起作用:
{ "query": { "filtered": { "filter": { "terms": { "feed_uids": [ "cs.IT" ] } } } } }
Run Code Online (Sandbox Code Playgroud)
但是,查询不匹配任何内容.我究竟做错了什么?
Ale*_*vik 19
在terms像您期望的筛选器的工作原理.我想你的问题是你有一个feed_uids使用标准分析仪的映射.
这是一个非常常见的问题,在这里有更深入的描述:对初学者进行Elasticsearch搜索疑难解答
这是一个可运行的示例,展示了如何"index": "not_analyzed"为字段指定它的工作方式:https://www.found.no/play/gist/bc957d515597ec8262ab
#!/bin/bash
export ELASTICSEARCH_ENDPOINT="http://localhost:9200"
# Create indexes
curl -XPUT "$ELASTICSEARCH_ENDPOINT/play" -d '{
"mappings": {
"type": {
"properties": {
"feed_uids": {
"type": "string",
"index": "not_analyzed"
}
}
}
}
}'
# Index documents
curl -XPOST "$ELASTICSEARCH_ENDPOINT/_bulk?refresh=true" -d '
{"index":{"_index":"play","_type":"type"}}
{"feed_uids":["math.CO","cs.IT"]}
{"index":{"_index":"play","_type":"type"}}
{"feed_uids":["cs.IT"]}
'
# Do searches
curl -XPOST "$ELASTICSEARCH_ENDPOINT/_search?pretty" -d '
{
"query": {
"filtered": {
"filter": {
"terms": {
"feed_uids": [
"cs.IT"
]
}
}
}
}
}
'
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7706 次 |
| 最近记录: |