gpt4 book ai didi

indexing - Elasticsearch 索引未分析

转载 作者:行者123 更新时间:2023-12-02 04:54:08 29 4
gpt4 key购买 nike

我是 Elastic Search 的新手,我在使用分析器时遇到了困难。

我正在创建这样的索引(要复制我的问题,您可以直接将以下代码复制并粘贴到您的控制台中。)

请阅读脚本中对我的问题和问题的评论。

#!/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"]

}
}
}'

谁能指出我做错了什么?

最佳答案

您应该在插入文档后立即插入一个sleep 1 命令,一切都会正常进行。

Elasticsearch 提供近乎实时的搜索 (read this)。每次索引文档时,Lucene 索引不会立即更新(根据 Elasticsearch 进行刷新)。索引刷新的频率可在索引级别配置。您还可以通过在每个 HTTP 请求中传递查询参数 refresh=true 来强制刷新索引,这将使 ES 更新索引。但是,根据您的要求,您可能会因此而开始受到性能影响。

有一个Refresh API

关于indexing - Elasticsearch 索引未分析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24698756/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com