elasticsearch - 方面的多个属性(elasticsearch)

标签 elasticsearch faceted-search

我有以下索引:

curl -XPUT "http://localhost:9200/test/" -d '
{
    "mappings": {
        "files": {
            "properties": {
                "name": {
                    "type": "string",
                    "index": "not_analyzed"
                },
                "owners": {
                    "type": "nested",
                    "properties": {
                        "name": {
                            "type":"string",
                            "index":"not_analyzed"
                        },
                        "mail": {
                            "type":"string",
                            "index":"not_analyzed"
                        }
                    }
                }
            }
        }
    }
}
'

带有示例文档:

curl -XPUT "http://localhost:9200/test/files/1" -d '
{
    "name": "first.jpg",
    "owners": [
        {
            "name": "John Smith",
            "mail": "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="deb4ad9ebba6bfb3aeb2bbf0bdb1b3" rel="noreferrer noopener nofollow">[email protected]</a>"
        },
        {
            "name": "Joe Smith",
            "mail": "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="771d18120437120f161a071b125914181a" rel="noreferrer noopener nofollow">[email protected]</a>"
        }
    ]
}
'

curl -XPUT "http://localhost:9200/test/files/2" -d '
{
    "name": "second.jpg",
    "owners": [
        {
            "name": "John Smith",
            "mail": "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a4ced7e4c1dcc5c9d4c8c18ac7cbc9" rel="noreferrer noopener nofollow">[email protected]</a>"
        },
        {
            "name": "Ann Smith",
            "mail": "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="cfaebc8faab7aea2bfa3aae1aca0a2" rel="noreferrer noopener nofollow">[email protected]</a>"
        }
    ]
}
'

curl -XPUT "http://localhost:9200/test/files/3" -d '
{
    "name": "third.jpg",
    "owners": [
        {
            "name": "Kate Foo",
            "mail": "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="1e75785e7b667f736e727b307d7173" rel="noreferrer noopener nofollow">[email protected]</a>"
        }
    ]
}
'

我需要找到与某些查询匹配的所有所有者,比如说“mit”:

curl -XGET "http://localhost:9200/test/files/_search" -d '
{
    "facets": {
        "owners": {
            "terms": {
                "field": "owners.name"
            },
            "facet_filter": {
                "query": {
                    "query_string": {
                        "query": "*mit*",
                        "default_field": "owners.name"
                    }
                }
            },
            "nested": "owners"
        }
    }
}
'

这给了我以下结果:

{
  "facets" : {
    "owners" : {
      "missing" : 0,
      "_type" : "terms",
      "other" : 0,
      "total" : 4,
      "terms" : [
        {
          "count" : 2,
          "term" : "John Smith"
        },
        {
          "count" : 1,
          "term" : "Joe Smith"
        },
        {
          "count" : 1,
          "term" : "Ann Smith"
        }
      ]
    }
  },
  "timed_out" : false,
  "hits" : {...}
}

而且没关系。 但我真正需要的是让所有者提供他们的电子邮件地址(对于方面中的每个条目,我需要结果中的附加字段)。 可以实现吗?

最佳答案

我认为不可能吗?根据您的需要,我会有

  1. 创建一个包含姓名和电子邮件的复合字段,并在该字段上执行构面操作,或者
  2. 除了构面之外还运行查询并从查询结果中提取它,但这显然不可扩展
  3. 两步操作,获取构面,构建所需的查询并合并结果。

关于elasticsearch - 方面的多个属性(elasticsearch),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15277603/

相关文章:

python - 使用 Python 连接到 AWS Elasticsearch 实例

magento - 有没有办法将 Magento 动态分面搜索页面更改为静态页面?

Elasticsearch 术语方面不显示否定术语

javascript - 如何禁用 winston elasticstack 客户端和传输生成的调试控制台输出?

elasticsearch - 在elasticsearch中按日期过滤

c# - C#NEST ElasticSearch Default_Search分析器

ElasticSearch - 无法解析搜索源。预期的字段名称但得到了 [START_OBJECT]

database - 什么是分面搜索?

solr - 使用 SOLR 对短语进行 Sitecore 分面

angularjs - 使用elasticsearch进行分面搜索