1

私はcouchDBを使用しており、クエリにnGramsを使用しようとしているため、リバープラグインでESを使用しています。誰かがスペースを入力すると、クエリが正しく機能しないという事実を除いて、基本的に必要なことはすべて実行しました。これは、ES がクエリのすべての要素をスペースで分割してトークン化するためです。

これが私がする必要があることです:

  • 文字列内のテキストの一部を照会します。

    クエリ: "Hello Wor" 応答: "Hello World, Hello Word" / 除外 "Hello, World, Word"

  • 指定した基準で結果を並べ替えます。

  • 大文字小文字を区別しません。

この質問に従って、私が行ったことは次のとおりです。ElasticSearchで単語の一部を検索する方法

curl -X PUT  'localhost:9200/_river/myDB/_meta' -d '
{
"type" : "couchdb",
"couchdb" : {
    "host" : "localhost",
    "port" : 5984,
    "db" : "myDB",
    "filter" : null
},
   "index" : {
    "index" : "myDB",
    "type" : "myDB",
    "bulk_size" : "100",
    "bulk_timeout" : "10ms",
    "analysis" : {
               "index_analyzer" : {
                          "my_index_analyzer" : {
                                        "type" : "custom",
                                        "tokenizer" : "standard",
                                        "filter" : ["lowercase", "mynGram"]
                          }
               },
               "search_analyzer" : {
                          "my_search_analyzer" : {
                                        "type" : "custom",
                                        "tokenizer" : "standard",
                                        "filter" : ["standard", "lowercase", "mynGram"]
                          }
               },
               "filter" : {
                        "mynGram" : {
                                   "type" : "nGram",
                                   "min_gram" : 2,
                                   "max_gram" : 50
                        }
               }
    }
}
}
'

次に、並べ替え用のマッピングを追加します。

curl -s -XGET 'localhost:9200/myDB/myDB/_mapping' 
{
"sorting": {
       "Title": {
            "fields": {
                "Title": {
                     "type": "string"
                  }, 
                "untouched": {
                    "include_in_all": false, 
                    "index": "not_analyzed", 
                    "type": "string"
                    }
               }, 
              "type": "multi_field"
         },
        "Year": {
              "fields": {
                   "Year": {
                       "type": "string"
                       }, 
                       "untouched": {
                           "include_in_all": false, 
                           "index": "not_analyzed", 
                           "type": "string"
                         }
                     }, 
                    "type": "multi_field"
        }
     }
    }
   }'

完全にするために使用するすべての情報を追加しました。とにかく、このセットアップでは、結果を取得しようとするたびに、うまくいくはずだと思いますが、クエリを分割するためにスペースが引き続き使用されます。例:

  http://localhost:9200/myDB/myDB/_search?q=Title:(Hello%20Wor)&pretty=true

"Hello" と "Wor" を含むものをすべて返します (通常、括弧は使用しませんが、例で見たことがありますが、結果は非常に似ているようです)。

これは私をかなり悩ませているので、どんな助けも本当に感謝しています。

更新: 最後に、nGram は必要ないことに気付きました。通常のインデックスで十分です。クエリの空白を「 AND 」に置き換えるだけでうまくいきます。

例:

 Query: "Hello World"  --->  Replaced as "(*Hello And World*)"
4

1 に答える 1

1

現在、Elastic Searchの設定はありませんが、これはdocから役立つかもしれません。

http://www.elasticsearch.org/guide/reference/query-dsl/match-query.html

Types of Match Queries

boolean

The default match query is of type boolean. It means that the text provided is analyzed and the analysis process constructs a boolean query from the provided text. The operator flag can be set to or or and to control the boolean clauses (defaults to or).

The analyzer can be set to control which analyzer will perform the analysis process on the text. It default to the field explicit mapping definition, or the default search analyzer.

fuzziness can be set to a value (depending on the relevant type, for string types it should be a value between 0.0 and 1.0) to constructs fuzzy queries for each term analyzed. The prefix_length and max_expansions can be set in this case to control the fuzzy process. If the fuzzy option is set the query will use constant_score_rewrite as its rewrite method the rewrite parameter allows to control how the query will get rewritten.

Here is an example when providing additional parameters (note the slight change in structure, message is the field name):

{
    "match" : {
        "message" : {
            "query" : "this is a test",
            "operator" : "and"
        }
    }
}
于 2012-10-27T20:32:19.613 に答える