The elasticsearch version I used is es2.2. I type the same code as the official tutorial for full-text search. (https://www.elastic.co/guide/en/elasticsearch/guide/current/match-query.html)
It seems the full-text doesn't work for me. What's wrong with my setting? Thanks!
The code I type is below:
curl -XDELETE 'localhost:9200/my_index '
curl -XPUT 'localhost:9200/my_index ' -d '
{
"settings": { "number_of_shards": 1 }
}'
curl -XPOST 'localhost:9200/my_index/my_type/_bulk' -d'
{ "index": { "_id": 1 }}
{ "title": "The quick brown fox" }
{ "index": { "_id": 2 }}
{ "title": "The quick brown fox jumps over the lazy dog" }
{ "index": { "_id": 3 }}
{ "title": "The quick brown fox jumps over the quick dog" }
{ "index": { "_id": 4 }}
{ "title": "Brown fox brown dog" }'
curl -XGET 'localhost:9200/my_index/my_type/_search' -d'
{
"query": {
"match": {
"title": "QUICK!"
}
}
}'
The returned result is :
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"failed": 0
},
"hits": {
"total": 0,
"max_score": null,
"hits": []
}
}
I can get only one hit when I input the exact query, which is stored in the index.
curl -XGET 'localhost:9200/my_index/my_type/_search' -d'
{
"query": {
"match": {
"title": "The quick brown fox"
}
}
}'
The output is: {"took":1,"timed_out":false,"_shards":{"total":1,"successful":1,"failed":0},"hits":{"total":1,"max_score":1.4054651,"hits":[{"_index":"my_index","_type":"my_type","_id":"1","_score":1.4054651,"_source":{ "title": "The quick brown fox" }}]}}
I also test the analyzer:
curl -XGET 'localhost:9200/_analyze' -d'
{
"analyzer": "standard",
"text": "Text to analyze"
}'
curl: (6) Couldn't resolve host 'GET' {"tokens":[{"token":"text","start_offset":0,"end_offset":4,"type":"","position":0},{"token":"to","start_offset":5,"end_offset":7,"type":"","position":1},{"token":"analyze","start_offset":8,"end_offset":15,"type":"","position":2}]}
Is this error influence the result ?
quick
instead ofQUICK!
? Also, the last search you haveGET
two times in thecurl
command. – gitaarik