1

したがって、ElasticSearchインデックスが次のように定義されているとしましょう。

curl -XPUT 'http://localhost:9200/test' -d '{
  "mappings": {
    "example": {
      "properties": {
        "text": {
          "type": "string",
          "analyzer": "snowball"
        }
      }
    }
  }
}'

curl -XPUT 'http://localhost:9200/test/example/1' -d '{
  "text": "foo bar organization"
}'

スノーボールアナライザーで「foo組織」を検索すると、両方のキーワードが期待どおりに一致します。

curl -XGET http://localhost:9200/test/example/_search -d '{
  "query": {
    "text": {
      "_all": {
        "query": "foo organizations",
        "analyzer": "snowball"
      }
    }
  },
  "highlight": {
    "fields": {
      "text": {}
    }
  }
}'

{
  "took": 1,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "failed": 0
  },
  "hits": {
    "total": 1,
    "max_score": 0.015912745,
    "hits": [
      {
        "_index": "test",
        "_type": "example",
        "_id": "1",
        "_score": 0.015912745,
        "_source": {
          "text": "foo bar organization"
        },
        "highlight": {
          "text": [
            "<em>foo</em> bar <em>organization</em>"
          ]
        }
      }
    ]
  }
}

しかし、「組織」だけを検索すると、まったく結果が得られません。これは非常に奇妙なことです。

curl -XGET http://localhost:9200/test/example/_search -d '{
  "query": {
    "text": {
      "_all": {
        "query": "organizations",
        "analyzer": "snowball"
      }
    }
  },
  "highlight": {
    "fields": {
      "text": {}
    }
  }
}'

{
  "took": 1,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "failed": 0
  },
  "hits": {
    "total": 0,
    "max_score": null,
    "hits": []
  }
}

ただし、「バー」を検索すると、次のようになります。

curl -XGET http://localhost:9200/test/example/_search -d '{
  "query": {
    "text": {
      "_all": {
        "query": "bars",
        "analyzer": "snowball"
      }
    }
  },
  "highlight": {
    "fields": {
      "text": {}
    }
  }
}'

{
  "took": 1,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "failed": 0
  },
  "hits": {
    "total": 1,
    "max_score": 0.10848885,
    "hits": [
      {
        "_index": "test",
        "_type": "example",
        "_id": "1",
        "_score": 0.10848885,
        "_source": {
          "text": "foo bar organization"
        },
        "highlight": {
          "text": [
            "foo <em>bar</em> organization"
          ]
        }
      }
    ]
  }
}

「バー」と「組織」の違いは、「組織」は「オルガン」に由来し、「バー」はそれ自体に由来するということだと思います。しかし、2番目の検索がヒットするように適切な動作を取得するにはどうすればよいですか?

4

2 に答える 2

1

テキスト「foobarorganization」は、フィールドテキストとフィールド_allの2回インデックスに登録されています。フィールドテキストはスノーボールアナライザーを使用しており、フィールド_allは標準アナライザーを使用しています。したがって、テストレコードの分析後、フィールド_allには「foo」、「bar」、および「organization」のトークンが含まれます。検索中に、指定されたスノーボールアナライザーは「foo」を「foo」に、「bars」を「bar」に、「organization」を「organ」に変換します。したがって、クエリ内の「foo」と「bars」という単語はテストレコードと一致しますが、「組織」という用語は一致しません。強調表示は、検索とは関係なく、フィールドごとに実行されます。

于 2012-03-14T13:18:19.030 に答える
0

検索時よりもインデックス時にアナライザーを使用することをお勧めします。テキストフィールドをスノーボールアナライザーにマッピングしてからインデックスを作成します。これにより、組織を含む組織のトークンがいくつか作成されます。

于 2014-03-06T15:52:48.707 に答える