gpt4 book ai didi

nested - 如何在ElasticSearch上对嵌套文档使用构面过滤

转载 作者:行者123 更新时间:2023-12-02 22:33:40 24 4
gpt4 key购买 nike

我有以下映射:

curl -XPUT 'http://localhost:9200/bookstore/user/_mapping' -d '
{
"user": {
"properties": {
"user_id": { "type": "integer" },
"gender": { "type": "string", "index" : "not_analyzed" },
"age": { "type": "integer" },
"age_bracket": { "type": "string", "index" : "not_analyzed" },
"current_city": { "type": "string", "index" : "not_analyzed" },
"relationship_status": { "type": "string", "index" : "not_analyzed" },
"books" : {
"type": "nested",
"properties" : {
"b_oid": { "type": "string", "index" : "not_analyzed" },
"b_name": { "type": "string", "index" : "not_analyzed" },
"bc_id": { "type": "integer" },
"bc_name": { "type": "string", "index" : "not_analyzed" },
"bcl_name": { "type": "string", "index" : "not_analyzed" },
"b_id": { "type": "integer" }
}
}
}
}
}'

现在,我尝试查询具有“gender”:“Male”,已购买某类别“bcl_name”:“Trivia”的书籍并显示“b_name”书籍标题的用户。我以某种方式无法运行它。

我有查询
curl -XGET 'http://localhost:9200/bookstore/user/_search?pretty=1' -d '{
"size": 0,
"from": 0,
"query": {
"filtered": {
"query": {
"terms": {
"gender": [
"Male"
]
}
}
}
},
"facets": {
"CategoryFacet": {
"terms": {
"field": "books.b_name",
"size": 5,
"shard_size": 1000,
"order": "count"
},
"nested": "books",
"facet_filter": {
"terms": {
"books.bcl_name": [
"Trivia"
]
}
}
}
}
}'

它返回一个结果,但是我不确定这是否正确。我查找了一些示例,并找到了这个示例( http://www.spacevatican.org/2012/6/3/fun-with-elasticsearch-s-children-and-nested-documents/)。我可以这样重写查询:
curl -XGET 'http://localhost:9200/bookstore/user/_search?pretty=1' -d '{
"size": 0,
"from": 0,
"query": {
"filtered": {
"query": {
"terms": {
"gender": [
"Male"
]
}
},
"filter": {
"nested": {
"path": "books",
"query": {
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"and": [
{
"term": {
"books.bcl_name": "Trivia"
}
}
]
}
}
}
}
}
}
},
"facets": {
"CategoryFacet": {
"terms": {
"field": "books.b_name",
"size": 5,
"shard_size": 1000,
"order": "count"
},
"nested": "books"
}
}
}'

显示不同的结果。

我,作为一个初学者,现在是迷失了。有人可以给我提示如何解决这个问题吗?在此先多谢!

最佳答案

第一个查询的意思是:

  • 搜索gender : "Male"
  • 的用户
  • 但是“CategoryFacet”包括gender : "Male" AND
    books.bcl_name : "Trivia"
  • 的计数

    因此,在结果集中,您将获得所有“男性”用户,但是CategoryFacet会为您提供“男性用户且其book.bcl_name为Trivia”的计数。

    在第二个查询中,您的“CategoryFacet”不包含额外的过滤。它只是从精确结果集中返回构面。

    关于nested - 如何在ElasticSearch上对嵌套文档使用构面过滤,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21143646/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com