2014-07-11 191 views
3

我是新來的彈性搜索,我很難與分析儀。彈性搜索索引未被分析

我創造這樣一個索引(複製我的問題,你可以複製和控制檯中的follwoing代碼直接粘貼。)

請閱讀劇本,我的問題和問題的意見。

#!/bin/bash 
# fails if the index doesn't exist but that's OK 
curl -XDELETE 'http://localhost:9200/movies/' 

# creating the index that will allow type wrapper, and generate _id automatically from the path 

curl -XPOST http://localhost:9200/movies -d '{ 
    "settings" : { 
     "number_of_shards" : 1, 
     "mapping.allow_type_wrapper" : true, 
     "analysis": { 
      "analyzer": { 
       "en_std": { 
        "type":"standard", 
        "stopwords": "_english_" 
       } 
      } 
     } 

    }, 
    "mappings" : { 
     "movie" : { 
      "_id" : { 
       "path" : "movie.id" 
      } 
     } 
    } 
}' 

# inserting some data 
curl -XPOST http://localhost:9200/movies/movie -d '{ 
    "movie" : { 
     "id" : 101, 
     "title" : "Bat Man", 
     "starring" : { 
      "firstname" : "Christian", 
      "lastname" : "Bale" 
     } 
    } 
}' 

#trying to get by ID ... \m/ works!!! 
curl -XGET http://localhost:9200/movies/movie/101 


# tryign to search using query_string ... \m/ works 
curl -XPOST http://localhost:9200/movies/movie/_search -d '{ 
    "query" : { 
     "query_string" : { 
      "query" : "bat" 
     } 
    } 
}' 

# when i try to search in a paricular field it fails. returns 0 hits 
curl -XPOST http://localhost:9200/movies/_search -d '{ 
    "query" : { 
     "query_string" : { 
      "query" : "bat", 
      "fields" : ["movie.title"] 

     } 
    } 
}' 


#I thought the analyzer was the problem, so i checked. 
curl 'http://localhost:9200/movies/movie/_search?pretty=true' -d '{ 
    "query" : { 
     "query_string" : { 
      "query" : "bat" 

     } 
    }, 
    "script_fields": { 
     "terms" : { 
      "script": "doc[field].values", 
      "params": { 
       "field": "movie.title" 
      } 
     } 

    } 
}' 

# The field wasn't analyzed. 
# the follwoing is the result 
#{ 
# "took" : 1, 
# "timed_out" : false, 
# "_shards" : { 
# "total" : 1, 
# "successful" : 1, 
# "failed" : 0 
# }, 
# "hits" : { 
# "total" : 1, 
# "max_score" : 0.13424811, 
# "hits" : [ { 
#  "_index" : "movies", 
#  "_type" : "movie", 
#  "_id" : "101", 
#  "_score" : 0.13424811, 
#  "fields" : { 
#  "terms" : [ "Bat Man" ] 
#  } 
# } ] 
# } 
#} 


# So i even tried the term as such... Nope didn't work :( 0 hits. 
curl -XPOST http://localhost:9200/movies/_search -d '{ 
    "query" : { 
     "query_string" : { 
      "query" : "Bat Man", 
      "fields" : ["movie.title"] 

     } 
    } 
}' 

任何人都可以指出我做錯了什麼?

+0

elasticsearch的哪個版本?你也可以嘗試運行'curl -Xget「http:// localhost:9200/movies/_analyze?text = Bat Man」'以查看你的默認分析器如何分析 – keety

+0

在運行0.90.11。是的。試過了。這個人完美地分析它。將它分成兩個小寫字母:蝙蝠,男人。但查詢不起作用 – raj

回答

0

您應該在插入文檔後立即插入sleep 1命令,並且所有內容都將工作。

Elasticsearch提供近乎實時的搜索(read this)。每次索引文檔時,Lucene索引都不會立即更新(以Elasticsearch方式刷新)。索引刷新的頻率可以在索引級別配置。您還可以通過將查詢參數refresh=true與每個HTTP請求一起傳遞來強制刷新索引,這將使ES更新索引。但是你可能會因爲這一點而開始受到影響,這取決於你的要求。還有Refresh API

+0

不,我試過了。這不是問題。即使過了一段時間,也會產生零點擊。 – raj

+0

您是否嘗試升級到最新版本?你的腳本在ES的1.1.x版本上爲我工作。 – vaidik