2013-02-14 120 views
0

我似乎無法弄清楚如何獲得elasticsearch(通過pyes訪問)來搜索複數/單數術語。例如,當我進入Monkies時,我想要得到帶有Belt的結果。我看過Elasticsearch not returning singular/plural matches,但似乎無法理解它。下面是一些捲曲陳述Elasticsearch搜索複數

curl -XDELETE localhost:9200/myindex 

curl -XPOST localhost:9200/myindex -d ' 
{"index": 
    { "number_of_shards": 1, 
    "analysis": { 
     "filter": { 
       "myfilter": { 
        "type" : "porter_stem", 
        "language" : "English" 
       } 
       }, 
     "analyzer": { 
      "default" : {      
       "tokenizer" : "nGram", 
       "filter" : ["lowercase", "myfilter"] 
       }, 
      "index_analyzer" : {      
       "tokenizer" : "nGram", 
       "filter" : ["lowercase", "myfilter"] 
       }, 
       "search_analyzer" : {              
        "tokenizer" : "nGram", 
        "filter" : ["lowercase", "myfilter"] 
       } 
     } 
    } 
    } 
} 
}' 

curl -XPUT localhost:9200/myindex/mytype/_mapping -d '{ 
    "tweet" : { 
     "date_formats" : ["yyyy-MM-dd", "dd-MM-yyyy"], 
     "properties" : { 
      "user": {"type":"string"}, 
      "post_date": {"type": "date"}, 
      "message" : {"type" : "string", "analyzer": "search_analyzer"} 
     } 
    }}' 

curl -XPUT 'http://localhost:9200/myindex/mytype/1' -d '{ 
"user" : "kimchy", 
"post_date" : "2009-11-15T14:12:12", 
"message" : "belt knife is a cool thing" 
}' 

curl -XPUT 'http://localhost:9200/myindex/mytype/2' -d '{ 
"user" : "alwild", 
"post_date" : "2009-11-15T14:12:12", 
"message" : "second message with nothing else" 
}' 

curl -XGET localhost:9200/myindex/mytype/_search?q=message:belts 

我它得到的地步,尋找皮帶給我一些結果...但現在它給了過多的結果。我必須做些什麼來讓它只返回那個有「帶」的條目呢?

回答

2

默認情況下,您的查詢是針對使用標準分析器的_all字段執行的,因此您沒有詞幹。嘗試使用諸如name:Monkies之類的查詢進行搜索。出於生產目的,請使用match查詢,該查詢將正確地將查詢和字段映射之間的分析器連接起來。

順便提一下,Elasticsearch可以非常容易地比較不同的分析設置。比較:

http://localhost:9200/_analyze?text=Monkies&analyzer=standard 

VS

http://localhost:9200/_analyze?text=Monkies&analyzer=snowball 
0

你可以減少一些curl調用,通過這個映射創建你的索引,索引一些數據,並執行一個搜索來顯示你不期望的結果?

+0

我編輯的問題,包括捲曲的供詞,以及改變了一點東西。它現在正在返回多個結果,但它返回了太多/不相關的結果。謝謝你的幫助。 – 2013-03-01 06:48:35