0

特殊文字を空白に置き換えて大文字に変換するアナライザーを作成しようとしています。その後、小文字で検索したい場合も機能するはずです。

マッピング アナライザー:

soundarya@soundarya-VirtualBox:~/Downloads/elasticsearch-2.4.0/bin$ curl -XPUT 'http://localhost:9200/aida' -d '{
  "settings": {
    "analysis": {
      "analyzer": {
        "my_analyzer": {
          "tokenizer": "standard",
          "char_filter": [
            "my_char_filter"
          ],
          "filter": [
            "uppercase"
            ]
        }
      },
      "char_filter": {
        "my_char_filter": {
          "type": "pattern_replace",
          "pattern": "(\\d+)-(?=\\d)",
          "replacement": "$1 "
        }
      }
    }
  }
}
'
{"acknowledged":true}


soundarya@soundarya-VirtualBox:~/Downloads/elasticsearch-2.4.0/bin$ curl -XPOST 'http://localhost:9200/aida/_analyze?pretty' -d '{
"analyzer":"my_analyzer",
"text":"My name is Soun*arya?jwnne&yuuk"
}'

特殊文字を空白に置き換えることで、単語を適切にトークン化しています。テキストから単語を検索しても、結果が得られません。

soundarya@soundarya-VirtualBox:~/Downloads/elasticsearch-2.4.0/bin$ curl -XGET 'http://localhost:9200/aida/_search' -d '{
"query":{
"match":{
"text":"My"
}
}
}'

上記の GET クエリから結果が得られません。次のような結果を得る:

soundarya@soundarya-VirtualBox:~/Downloads/elasticsearch-2.4.0/bin$ curl -XGET 'http://localhost:9200/aida/_search' -d '{
"query":{
"match":{
"text":"my"
}
}
}'
{"took":5,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":0,"max_score":null,"hits":[]}}

誰でもこれで私を助けることができます! ありがとうございました!

4

1 に答える 1

1

インデックスを作成した後、データのインデックスを作成していないようです。への呼び出し_analyzeはインデックスを作成しませんが、ES に送信したコンテンツがどのように分析されるかを示すだけです。

まず、定義したアナライザーを使用するマッピングを指定して、インデックスを作成する必要があります。

curl -XPUT 'http://localhost:9200/aida' -d '{
  "settings": {
    "analysis": {
      "analyzer": {
        "my_analyzer": {
          "tokenizer": "standard",
          "char_filter": [
            "my_char_filter"
          ],
          "filter": [
            "uppercase"
            ]
        }
      },
      "char_filter": {
        "my_char_filter": {
          "type": "pattern_replace",
          "pattern": "(\\d+)-(?=\\d)",
          "replacement": "$1 "
        }
      }
    }
  },
  "mappings": {                        <--- add a mapping type...
    "doc": {
      "properties": {
        "text": {                      <--- ...with a field...
          "type": "string",
          "analyzer": "my_analyzer"    <--- ...using your analyzer
        }
      }
    }
  }
}'

次に、新しい実際のドキュメントにインデックスを付けることができます。

curl -XPOST 'http://localhost:9200/aida/doc' -d '{
   "text": "My name is Soun*arya?jwnne&yuuk"
}'

最後に、次を検索できます。

curl -XGET 'http://localhost:9200/aida/_search' -d '{
  "query":{
    "match":{
      "text":"My"
    }
  }
}'
于 2016-09-23T14:14:53.087 に答える