2012-03-14 10 views
1

を使用した場合それでは、私はこのように定義されたElasticSearchインデックスを持っているとしましょう: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番目の検索ヒットを得るためには、どのように適切な振る舞いをするのですか?

答えて

1

テキスト「fooのバーの組織が」二度インデックス付けなっている - フィールドテキストにし、フィールド _all に。フィールドテキストはスノーボールアナライザーを使用しており、フィールド_allは標準アナライザーを使用しています。したがって、テストレコードを分析した後、フィールド_allには、トークン「foo」、「bar」、および「organization」が含まれています。検索中に指定された雪だるまアナライザは、「foo」を「foo」に、「bars」を「bar」に、「organization」を「organ」に変換します。したがって、クエリの単語「foo」と「bars」はテストレコードと一致し、「組織」という用語は一致しません。強調表示は、検索とは独立してフィールドごとに行われます。そのため、最初の結果で「組織」という単語が強調表示されています。

+0

これは意味があります、ありがとう。私のインデックスにある実際のトークンを見る方法はありますか?そして、私はESに** all **列のために雪ボールを使うように伝えることができますか? – tycooon

+0

インデックス内の実際のトークンを調べる簡単な方法はありませんが、Analyze API(http://www.elasticsearch.org/guide/reference/api/admin-indices- analyze.html)。インデックス作成時に* _all *フィールドにスノーボールアナライザーを設定することができます。https://gist.github.com/2043721あるいは、スノーボールは、すべてのフィールドhttps://gist.github.com/2043697のデフォルトのアナライザーとして設定することができます。 – imotov

0

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