2

私は次のインデックスを持っています:

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": "js@example.com"
        },
        {
            "name": "Joe Smith",
            "mail": "joes@example.com"
        }
    ]
}
'

curl -XPUT "http://localhost:9200/test/files/2" -d '
{
    "name": "second.jpg",
    "owners": [
        {
            "name": "John Smith",
            "mail": "js@example.com"
        },
        {
            "name": "Ann Smith",
            "mail": "as@example.com"
        }
    ]
}
'

curl -XPUT "http://localhost:9200/test/files/3" -d '
{
    "name": "third.jpg",
    "owners": [
        {
            "name": "Kate Foo",
            "mail": "kf@example.com"
        }
    ]
}
'

そして、いくつかのクエリに一致するすべての所有者を見つける必要があります。たとえば、「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" : {...}
}

そして、それは大丈夫です。しかし、私が必要としているのは、所有者に電子メールアドレスを提供することです(ファセットのエントリごとに、結果に追加のフィールドが必要です)。それは達成可能ですか?

4

1 に答える 1

4

不可能だと思いますか?あなたのニーズに応じて私は

  1. 名前とメールアドレスの両方を使用して複合フィールドを作成し、そのフィールドでファセットを実行するか、
  2. ファセットに加えてクエリを実行し、クエリ結果から抽出しますが、これは明らかにスケーラブルではありません
  3. 2つのステップ操作、ファセットの取得、必要なクエリの作成、結果のマージ。
于 2013-03-12T07:28:18.783 に答える