Tôi đoán bạn đang sử dụng standard
phân tích, trong đó chia thành hai http://example.dom
tokens - http
và example.com
. Bạn có thể xem http://localhost:9200/_analyze?text=http://example.com&analyzer=standard
.
Nếu bạn muốn chia url
, bạn cần sử dụng khác nhau analyzer hoặc chỉ định custom analyzer của riêng chúng tôi.
Bạn có thể xem làm cách nào để được url
lập chỉ mục với simple analyzer - http://localhost:9200/_analyze?text=http://example.com&analyzer=simple
. Như bạn có thể thấy, bây giờ là url
được lập chỉ mục dưới dạng ba mã số ['http', 'example', 'com']
. Nếu bạn không muốn chỉ mục mã thông báo như ['http', 'www']
v.v, bạn có thể chỉ định máy phân tích của mình với lowercase tokenizer (đây là mã được sử dụng trong máy phân tích đơn giản) và stop filter. Ví dụ một cái gì đó như thế này:
# 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"
}
}
}'
Chú ý: Nếu bạn không muốn sử dụng các tệp từ dừng ở đây là bài viết thú vị stop stopping stop words: a look at common terms query
nhờ @vhyza. Tôi đã cập nhật câu hỏi w/cách tôi tạo chỉ mục. Tôi có một thuộc tính lồng nhau và muốn dải html. –
Bạn được chào đón. Các thuộc tính lồng nhau sẽ ổn. Bạn có thể thêm 'char_filter' vào' lowercase_with_stopwords 'để tách html nếu bạn muốn. – vhyza