2013-09-24 32 views
12

Elastik aramada dizine eklenmiş bir belgenin website alanım var. Örnek değer: http://example.com. Sorun şu ki, example için arama yaptığımda, belge dahil değildir. Web sitesi/url alanı nasıl doğru bir şekilde haritalanır? - http ve example.comElastic Search'de dizin oluşturma/url

{ 
    "settings":{ 
    "index":{ 
     "analysis":{ 
     "analyzer":{ 
      "analyzer_html":{ 
        "type":"custom", 
        "tokenizer": "standard", 
       "filter":"standard", 
       "char_filter": "html_strip" 
      } 
     } 
     } 
    } 
    }, 
    "mapping":{ 
    "blogshops": { 
     "properties": { 
      "category": { 
       "properties": { 
        "name": { 
         "type": "string" 
        } 
       } 
      }, 
      "reviews": { 
       "properties": { 
        "user": { 
         "properties": { 
          "_id": { 
           "type": "string" 
          } 
         } 
        } 
       } 
      } 
     } 
    } 
    } 
} 

cevap

22

Sana iki dizgeciklerine http://example.dom böler standard analizörü, kullandığınız tahmin:

aşağıda endeksi oluşturdu. http://localhost:9200/_analyze?text=http://example.com&analyzer=standard bir göz atabilirsiniz.

url'u bölmek istiyorsanız, farklı analyzer'u kullanmanız veya kendi custom analyzer'umuzu belirtmeniz gerekir.

simple analyzer - http://localhost:9200/_analyze?text=http://example.com&analyzer=simple - http://localhost:9200/_analyze?text=http://example.com&analyzer=simple ile nasıl indekslenebilir url. Gördüğünüz gibi, şimdi ['http', 'example', 'com'] üç jeton olarak endekslenmiş url. ['http', 'www'] vb. Gibi simgeleri indekslemek istemiyorsanız, analiz cihazınızı lowercase tokenizer (basit analizörde kullanılan) ve stop filter ile belirtebilirsiniz.

# Delete index 
# 
curl -s -XDELETE 'http://localhost:9200/url-test/' ; echo 

# Create index with mapping and custom index 
# 
curl -s -XPUT 'http://localhost:9200/url-test/' -d '{ 
    "mappings": { 
    "document": { 
     "properties": { 
     "content": { 
      "type": "string", 
      "analyzer" : "lowercase_with_stopwords" 
     } 
     } 
    } 
    }, 
    "settings" : { 
    "index" : { 
     "number_of_shards" : 1, 
     "number_of_replicas" : 0 
    }, 
    "analysis": { 
     "filter" : { 
     "stopwords_filter" : { 
      "type" : "stop", 
      "stopwords" : ["http", "https", "ftp", "www"] 
     } 
     }, 
     "analyzer": { 
     "lowercase_with_stopwords": { 
      "type": "custom", 
      "tokenizer": "lowercase", 
      "filter": [ "stopwords_filter" ] 
     } 
     } 
    } 
    } 
}' ; echo 

curl -s -XGET 'http://localhost:9200/url-test/_analyze?text=http://example.com&analyzer=lowercase_with_stopwords&pretty' 

# Index document 
# 
curl -s -XPUT 'http://localhost:9200/url-test/document/1?pretty=true' -d '{ 
    "content" : "Small content with URL http://example.com." 
}' 

# Refresh index 
# 
curl -s -XPOST 'http://localhost:9200/url-test/_refresh' 

# Try to search document 
# 
curl -s -XGET 'http://localhost:9200/url-test/_search?pretty' -d '{ 
    "query" : { 
    "query_string" : { 
     "query" : "content:example" 
    } 
    } 
}' 

NOT: engellenecek kelime burada kullanmak beğenmezseniz olduğu ilginç bir yazı stop stopping stop words: a look at common terms query

+0

sayesinde @vhyza böyle örnek bir şey için. İndeksi nasıl oluşturduğum sorusunu güncelledim. İç içe geçmiş bir mülküm var ve html'yi soymak istiyorum. –

+0

Bir şey değil. İç içe geçmiş özellikler iyi olmalıdır. İsterseniz html'yi şeritlemek için 'colour_with_stopwords''de' char_filter' öğesini ekleyebilirsiniz. – vhyza