2

ElasticSearchに次のマッピングがあるとしましょう。

{
  "content": {
    "properties": {
      "id": {
        "type": "string",
        "index": "not_analyzed",
        "store": "yes"
      },
      "locale_container": {
        "type": "object",
        "properties": {
          "english": {
            "type": "object",
            "properties": {
              "title": {
                "type": "string",
                "index_analyzer": "english",
                "search_analyzer": "english",
                "index": "analyzed",
                "term_vector": "with_positions_offsets",
                "store": "yes"
              },
              "text": {
                "type": "string",
                "index_analyzer": "english",
                "search_analyzer": "english",
                "index": "analyzed",
                "term_vector": "with_positions_offsets",
                "store": "yes"
              }
            }
          },
          "german": {
            "type": "object",
            "properties": {
              "title": {
                "type": "string",
                "index_analyzer": "german",
                "search_analyzer": "german",
                "index": "analyzed",
                "term_vector": "with_positions_offsets",
                "store": "yes"
              },
              "text": {
                "type": "string",
                "index_analyzer": "german",
                "search_analyzer": "german",
                "index": "analyzed",
                "term_vector": "with_positions_offsets",
                "store": "yes"
              }
            }
          },
          "russian": {
            "type": "object",
            "properties": {
              "title": {
                "type": "string",
                "index_analyzer": "russian",
                "search_analyzer": "russian",
                "index": "analyzed",
                "term_vector": "with_positions_offsets",
                "store": "yes"
              },
              "text": {
                "type": "string",
                "index_analyzer": "russian",
                "search_analyzer": "russian",
                "index": "analyzed",
                "term_vector": "with_positions_offsets",
                "store": "yes"
              }
            }
          },
          "italian": {
            "type": "object",
            "properties": {
              "title": {
                "type": "string",
                "index_analyzer": "italian",
                "search_analyzer": "italian",
                "index": "analyzed",
                "term_vector": "with_positions_offsets",
                "store": "yes"
              },
              "text": {
                "type": "string",
                "index_analyzer": "italian",
                "search_analyzer": "italian",
                "index": "analyzed",
                "term_vector": "with_positions_offsets",
                "store": "yes"
              }
            }
          }
        }
      }
    }
  }
}

特定のユーザーがインデックスを照会すると、設定から彼女の文化を取得できます。つまり、使用するアナライザーがわかります。自分の言語(たとえばドイツ語)の「タイトル」フィールドと「テキスト」フィールドのみを検索し、ドイツ語アナライザーを使用して検索クエリをトークン化するクエリを作成するにはどうすればよいですか?

4

1 に答える 1

1

例を簡略化して、standard「英語」にはアナライザーを使用simpleし、「フランス語」には(停止せずに)アナライザーを使用します。このようなドキュメントの場合:

{
  id: "abc",
  locale_container: {
    english: {
      title: "abc to ABC",
      text: ""
    },
    french: {
      title: "def to DEF",
      text: ""
    }
  }
}

次のクエリでうまくいきます。

  • locale_container.english.title:abc->ドキュメントを返します
  • locale_container.french.title:def->ドキュメントも返します
  • locale_container.english.title:to->「to」はストップワードであるため、何も返されません
  • locale_container.french.title:to->ドキュメントを返します
于 2011-09-14T13:06:29.903 に答える