栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

匹配完整的复杂嵌套集合项,而不是通过Elastic Search匹配单独的成员

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

匹配完整的复杂嵌套集合项,而不是通过Elastic Search匹配单独的成员

您是正确的,它只应查找嵌套文档具有value1和value2的文档。

您可以通过合理运行以下命令(chrome插件)来观察这是Elasticsearch的行为:

PUT http://localhost:9200/nested_example{    "mappings": {        "indexentry" : { "properties": {     "nestedCollection": {         "type": "nested",         "properties": {  "prop1" : { "type": "string", "index": "not_analyzed" },  "prop2" : { "type": "string", "index": "not_analyzed" }         }     } }         }    }}POST http://localhost:9200/nested_example/indexentry/1{    "nestedCollection": [        { "prop1" : "A", "prop2" : "A" },        { "prop1" : "B", "prop2" : "B" }    ]}POST http://localhost:9200/nested_example/indexentry/2{    "nestedCollection": [        { "prop1" : "C", "prop2" : "C" },        { "prop1" : "D", "prop2" : "D" }    ]}POST http://localhost:9200/nested_example/indexentry/_search{    "query": {        "nested": {"path": "nestedCollection","query": {     "bool": {         "must": [ {     "term": {        "nestedCollection.prop1": {"value": "A"        }     } }, {     "term": {        "nestedCollection.prop2": {"value": "A"        }     } }         ]     }}        }    }}

先前的查询将仅找到文档,

1
但是一旦您更改术语查询
nestedColleciton.prop2
以查找
B
而不是
A
您,将不再获得预期的任何响应。

如果我更新该示例以使其更符合您的映射和查询,则无法重现您的见证行为:

PUT http://localhost:9200/nested_example{   "settings": {      "analysis": {         "tokenizer": { "my_ngram": {    "type": "nGram",    "min_gram": "1",    "max_gram": "15" }         },         "analyzer": { "my_index_analyzer_1": {    "type": "custom",    "tokenizer": "my_ngram",    "filters": [       "lowercase"    ] }, "my_search_analyzer_1": {    "type": "custom",    "tokenizer": "whitespace",    "filters": [       "lowercase"    ] }         }      }   },   "mappings": {      "indexentry": {         "properties": { "nestedCollection": {    "type": "nested",    "properties": {       "prop1": {          "type": "string",          "index_analyzer": "my_index_analyzer_1",          "search_analyzer": "my_search_analyzer_1"       },       "prop2": {          "type": "string",          "analyzer": "keyword"       }    } }         }      }   }}POST http://localhost:9200/nested_example/indexentry/1{    "nestedCollection": [        { "prop1" : "value1", "prop2" : "value1" },        { "prop1" : "value2", "prop2" : "value2" }    ]}POST http://localhost:9200/nested_example/indexentry/2{    "nestedCollection": [        { "prop1" : "value3", "prop2" : "value3" },        { "prop1" : "value4", "prop2" : "value4" }    ]}POST http://localhost:9200/nested_example/indexentry/_search{    "query": {        "nested": {"path": "nestedCollection","query": {     "bool": {         "must": [ {     "term": {        "prop1": {"value": "value1"        }     } }, {     "query_string": {         "fields": [ "prop2"         ],         "query": "value1"     } }         ]     }}        }    }}

您可以更新前面的示例以更好地重现您的情况吗?

在NEST中,您可以将查询重写为:

client.Search<IndexEntry1>(d => d    .Query(query => query        .Nested(n => n .Path(p => p.NestedProperty1) .Query(q =>      q.Term(p => p.NestedProperty1.First().Member1, "value1")     && q.QueryString(s => s         .onField(p => p.NestedPropery1.First().Member2)         .Query("value2")     ) )        )    );

类型强,嵌套少。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/415571.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号