Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why ElasticSearch is not finding my term

I just installed and testing elastic search it looks great and i need to know some thing i have an configuration file

elasticsearch.json in config directory

{    
"network" : {
    "host" : "127.0.0.1"
},
"index" : {
    "number_of_shards": 3,
    "number_of_replicas": 1,
    "refresh_interval" : "2s",        
    "analysis" : {
        "analyzer" : {                
            "index_analyzer" : {                    
                "tokenizer" : "nGram",
                "filter" : ["lowercase"]
            },
            "search_analyzer" : {                                                    
                "tokenizer" : "nGram",
                "filter" : ["lowercase"]
            }
        },                               
        "// you'll need lucene dep for this: filter" : {                
            "snowball": {
                "type" : "snowball",
                "language" : "English"
            }
        }
    }
}

}

and i have inserted an doc that contains a word searching if i search for keyword search it says nothing found...

wont it stem before indexing or i missed some thing in config ....

like image 928
raagavan Avatar asked Feb 12 '11 22:02

raagavan


People also ask

Why is Elasticsearch not returning all results?

The reason might be that you haven't provided the size parameter in the query. This limits the result count to 10 by default. Out of all the results the top 10 might be from the two index even thought the match is present in third index as well.

What is term in Elasticsearch?

You can use the term query to find documents based on a precise value such as a price, a product ID, or a username. Avoid using the term query for text fields. By default, Elasticsearch changes the values of text fields as part of analysis. This can make finding exact matches for text field values difficult.

What is difference between term and terms in Elasticsearch?

Term query return documents that contain one or more exact term in a provided field. The terms query is the same as the term query, except you can search for multiple values. Warning: Avoid using the term query for text fields.


2 Answers

How looks your query?

your config does not look good. try:

 ...
"index_analyzer" : {                    
   "tokenizer" : "nGram",
   "filter" : ["lowercase", "snowball"]
},
 "search_analyzer" : {                                                    
    "tokenizer" : "nGram",
    "filter" : ["lowercase", "snowball"]
}
},
"filter" : {
                "snowball": {
                    "type" : "snowball",
                    "language" : "English"
                }
            }
like image 110
Karussell Avatar answered Oct 03 '22 05:10

Karussell


I've had trouble overriding the "default_search" and "default_index" analyzer as well.

This works though. You can add "index_analyzer" to default all string fields with unspecified analyzers within a type, if need be.

curl -XDELETE localhost:9200/twitter

curl -XPOST localhost:9200/twitter -d '
{"index": 
  { "number_of_shards": 1,
    "analysis": {
       "filter": {
                "snowball": {
                    "type" : "snowball",
                    "language" : "English"
                }
                 },
       "analyzer": { "a2" : {
                    "type":"custom",
                    "tokenizer": "standard",
                    "filter": ["lowercase", "snowball"]
                    }
                  }
     }
  }
}
}'

curl -XPUT localhost:9200/twitter/tweet/_mapping -d '{
    "tweet" : {
        "date_formats" : ["yyyy-MM-dd", "dd-MM-yyyy"],
        "properties" : {
            "user": {"type":"string"},
            "message" : {"type" : "string", "analyzer":"a2"}
        }
    }}'

curl -XPUT http://localhost:9200/twitter/tweet/1 -d '{ "user": "kimchy", "post_date": "2009-11-15T13:12:00", "message": "Trying out searching teaching, so far so good?" }'

curl -XGET localhost:9200/twitter/tweet/_search?q=message:search 

curl -XGET localhost:9200/twitter/tweet/_search?q=message:try 
like image 43
bdargan Avatar answered Oct 03 '22 07:10

bdargan