elasticsearch ElasticSearch:是否在_all中包含嵌套字段?
我的文档如下所示:elasticsearch ElasticSearch:是否在_all中包含嵌套字段?,elasticsearch,nested,elasticsearch,Nested,我的文档如下所示: {"foo" : "blah blah blah", "bar" : "bla bla bla", "baz" : [{"href" : "someid"}, {"href" : "otherid"}, ...], ... } "datasets" : { "properties" : { "href" : { "include_in_all" : true, "index" : "not_analyzed",
{"foo" : "blah blah blah",
"bar" : "bla bla bla",
"baz" : [{"href" : "someid"}, {"href" : "otherid"}, ...],
... }
"datasets" : {
"properties" : {
"href" : {
"include_in_all" : true,
"index" : "not_analyzed",
"type" : "string"
}
},
"type" : "nested"
},
我想进行搜索,查找id
出现在href
子文档之一中的所有文档。如果我在映射中将baz.href
设置为未分析,我可以使用术语查询搜索baz.href
然而,我真正想要的是能够搜索这个ID,无论它出现在哪里。它可以在baz.href
,qux.href
,或者随便什么.href
。在\u all
中搜索完全可以接受
然而,我就是做不到这一点。我永远不会得到任何结果,除非我在baz.href
上搜索
我尝试在映射中的baz
上设置include_in_all
,但没有成功。我尝试将其设置为baz.href
,但也没有成功
我知道我可以在顶层的一个单独的all_hrefs
字段中复制ID,但这不必要地破坏了文档,而且看起来很难看。参考列表可能相当大。我还可以解析自己的映射并在那里找到所有href
字段,这样我就可以在查询中明确列出所有href
字段,但随着数据模型的增长,这最终将无法扩展
帮忙
更新:数据集字段的映射(以及包含href
的所有其他字段如下所示):
我尝试过删除嵌套的和删除包含在所有中的,但没有任何区别。当我使用嵌套
时,我可以使用嵌套查询,但是路径
必须设置为数据集
,因为*
失败,因为并非所有字段都包含嵌套对象。使用提供的映射:
$ curl -XPOST 'localhost:9200/datasets/data?pretty=true' -d '
{
"datasets" : {
"properties" : {
"href" : {
"include_in_all" : false,
"index" : "not_analyzed",
"type" : "string"
}
},
"type" : "nested"
}
}'
当我为这些文档编制索引时:
$ curl -XPOST 'localhost:9200/datasets/data' -d '
{
"foo": "blah blah blah",
"bar": "bla bla bla",
"baz": [
{
"href": "someid"
},
{
"href": "otherid"
}
],
"quux": {
"href": "thisid"
},
"whatever": {
"href": "thatid"
}
}'
$ curl -XPOST 'localhost:9200/datasets/data' -d '
{
"foo": "argh argh argh",
"bar": "arg arg arg",
"baz": [
{
"href": "funkyid"
},
{
"href": "thisid"
}
],
"quux": {
"href": "hipsterid"
},
"whatever": {
"href": "coolid"
}
}'
我能够正确地搜索href字段:
$ curl -XPOST 'localhost:9200/datasets/data/_search?pretty=true' -d '{
"query": {
"query_string": {
"query": "thisid",
"fields": ["*.href"]
}
}
}'
因此,无需在\u all
字段中对它们进行索引
我的测试是在Elasticsearch 5.2.1上完成的
仅供参考,我在这里找到了问题的解决方案:
不幸的是,这对我不起作用。不同之处在于,在我的例子中,href
子字段具有索引:not_analysisd
,这对于避免类似ID的误报是必要的。我在术语查询中尝试了*.href
,但没有成功。我还尝试在query\u字符串中设置analyzer:keyword
,但也没有成功。不过,非常感谢您的尝试!然后,您可以转储用于该索引的映射示例吗?这将有助于重现问题并进一步帮助排除故障。我用5.1再次尝试了你的建议,我确实得到了搜索结果,但我得到的结果太多了。我想按ID搜索,但搜索会找到相似但不完全相同的值。