私はElasticSearchを使用してpythonで検索システムを構築しています。私はcsvを読み込み、検索用のインデックスを作成しました。私が使用して検索ないとき Elasticsearchで検索を適用するには、ホワイトスペースの有無にかかわらず、
:正確な製品はCSVでありますので、これは正常に動作し
res = es.search(index="product-index", doc_type="product-index", body={"query": {"match": {"product": "DD 350"}}})
from elasticsearch import helpers, Elasticsearch
import csv
es = Elasticsearch()
with open('/Users/anubhav/Office/elasticsearch-5.6.0/all_products.csv') as f:
reader = csv.DictReader(f)
helpers.bulk(es, reader, index='product-index', doc_type='product-index')
es.indices.create(
index='product-index',
body={
"settings": {
"analysis": {
"analyzer": {
"my_analyzer": {
"tokenizer": "my_tokenizer"
}
},
"tokenizer": {
"my_tokenizer": {
"type": "edge_ngram",
"min_gram": 2,
"max_gram": 10,
"token_chars": [
"letter",
"digit",
"whitespace"
]
}
}
}
}
},
# Will ignore 400 errors, remove to ensure you're prompted
ignore=400
)
response = es.search(
index='product-index',
body={
"query": {
"match": {
"product": "PD5MP2 price"
}
},
"aggs": {
"top_10_states": {
"terms": {
"field": "state",
"size": 10
}
}
}
}
)
print response
csvファイルは次のように見えます。しかし、私はクエリを変更するとき
res = es.search(index="product-index", doc_type="product-index", body={"query": {"match": {"product": "DD350"}}})
それは動作しません。誰かがこれで私を助けてくれますか?
私は現在使用しているコードで質問を更新しました。しかし、設定で "ignore 400"行を削除すると、 "index already exists"というエラーが表示されます。これについてトークナイザを提案してもらえますか? – bazinga