我将我的问题改为完整的卷曲娱乐脚本.这样可以更容易地重现问题(使用自定义分析器搜索失败).我正在使用最新的ES版本
curl -XDELETE "http://localhost:9200/test_shingling"
Run Code Online (Sandbox Code Playgroud)
curl -XPOST "http://localhost:9200/test_shingling/" -d '{
"settings": {
"index": {
"number_of_shards": 10,
"number_of_replicas": 1
},
"analysis": {
"analyzer": {
"ShingleAnalyzer": {
"tokenizer": "BreadcrumbPatternAnalyzer",
"filter": [
"standard",
"lowercase",
"filter_stemmer",
"filter_shingle"
]
}
},
"filter": {
"filter_shingle": {
"type": "shingle",
"max_shingle_size": 2,
"min_shingle_size": 2,
"output_unigrams": false
},
"filter_stemmer": {
"type": "porter_stem",
"language": "English"
}
},
"tokenizer": {
"BreadcrumbPatternAnalyzer": {
"type": "pattern",
"pattern": " |\\$\\$\\$"
}
}
}
}
}'
Run Code Online (Sandbox Code Playgroud)
curl -XPOST "http://localhost:9200/test_shingling/item/_mapping" -d '{
"item": { …Run Code Online (Sandbox Code Playgroud) 我试图_timestamp在索引上定义属性.首先,我创建索引
curl -XPUT 'http://elasticsearch:9200/ppe/'
来自服务器的响应: {"ok":true,"acknowledged":true}
然后我尝试用a定义映射 _timestamp
curl -Xput 'http://elasticsearch:9200/ppe/log/_mapping' -d '{
"log": {
"properties": {
"_ttl": {
"enabled": true
},
"_timestamp": {
"enabled": true,
"store": "yes"
},
"message": {
"type": "string",
"store": "yes"
},
"appid": {
"type": "string",
"store": "yes"
},
"level": {
"type": "integer",
"store": "yes"
},
"logdate": {
"type": "date",
"format": "date_time_no_millis",
"store": "yes"
}
}
}
}'
Run Code Online (Sandbox Code Playgroud)
我收到服务器的答复
{
"error": "MapperParsingException[No type specified for property [_timestamp]]",
"status": 400
}
Run Code Online (Sandbox Code Playgroud)
我的映射有什么问题?
目前令我困惑的是,在查询中我添加了category_id10 的提升,这比其他提升要高得多.来自另一个类别"Tai Chi"的项目以某种方式到达结果的顶部.
我有一个映射:
{
"the_items": {
"item": {
"properties": {
"brand_id": {
"type": "integer"
},
"category_id": {
"type": "integer"
},
"description": {
"type": "multi_field",
"fields": {
"description": {
"type": "string",
"analyzer": "full_title"
}
}
},
"title": {
"type": "multi_field",
"fields": {
"title": {
"type": "string",
"analyzer": "full_title"
},
"partial_title": {
"type": "string",
"index_analyzer": "partial_title",
"search_analyzer": "full_title",
"include_in_all": false
}
}
},
"updated_at": {
"type": "string"
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我正在运行以下查询:
curl -XGET 'http://localhost:9200/austin_items/_search?pretty=true' -d '{
"query": …Run Code Online (Sandbox Code Playgroud) 我正在通过ElasticSearch进行文本搜索,并且使用术语类型查询时出现问题.我在下面做的基本上是,
那么,为什么会这样呢?以及如何解决它.
? curl -XPOST 'http://localhost:9200/test/test/' -d '{ "name" : "??" }'
{
"ok": true,
"_index": "test",
"_type": "test",
"_id": "VdV8K26-QyiSCvDrUN00Nw",
"_version": 1
}
Run Code Online (Sandbox Code Playgroud)
? curl -XGET 'http://localhost:9200/test/test/_mapping?pretty=1'
{
"test" : {
"properties" : {
"name" : {
"type" : "string"
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
? curl -XGET 'http://localhost:9200/test/test/_search?pretty=1'
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 1.0,
"hits": [
{
"_index": "test",
"_type": "test",
"_id": …Run Code Online (Sandbox Code Playgroud) 我已经拥有MongoDB并使用Mongoriver安装了Elasticsearch .所以我建立了我的河流:
$ curl -X PUT localhost:9200/_river/database_test/_meta -d '{
"type": "mongodb",
"mongodb": {
"servers": [
{
"host": "127.0.0.1",
"port": 27017
}
],
"options": {
"secondary_read_preference": true
},
"db": "database_test",
"collection": "event"
},
"index": {
"name": "database_test",
"type": "event"
}
}'
Run Code Online (Sandbox Code Playgroud)
我只是想得到country:Canada我尝试过的事件:
$ curl -XGET 'http://localhost:9200/database_test/_search?q=country:Canada'
Run Code Online (Sandbox Code Playgroud)
我得到:
{
"took": 2,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 0,
"max_score": null,
"hits": []
}
}
Run Code Online (Sandbox Code Playgroud)
我在网上搜索,我读到我应该首先用Elasticsearch索引我的收藏(丢失链接).我应该索引我的Mongodb吗?如何从现有的MongoDB集合中获取结果?
我想要一个过滤器来返回带're_max' > 100和的文件language_id = 28.我是这样做的:
{
"query": {
"filtered": {
"filter": {
"range": {
"re_max": {
"gt": 100
}
},
"term": {
"language_id": 28
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
但似乎不正确.我应该怎么纠正呢?
这是错误:
{
"error": "SearchPhaseExecutionException[Failed to execute phase [query], all shards failed;
shardFailures {[WkgqspjtQzmPkW-YdvE1Qg][rep][0]: SearchParseException[[rep][0]:
from[-1],size[-1]:
Parse Failure [Failed to parse source [
{
"query": {
"filtered": {
"filter": {
"or": [
"range":
{
"re_max": {
"gt": 100
}
},
"term":
{
"language_id": 28
}
]
} …Run Code Online (Sandbox Code Playgroud) 所以我有一个字段存储格式的值:number/year,如23/2014,24/2014,12/2015等等......
因此,如果此字段被映射为not_analyzed一个,我可以使用术语过滤器进行精确值搜索,如果我搜索该精确结构中的值(类似于1/2014,15/2014,...)它可以工作,就像sql equals(=).
{
"query": {
"filtered": {
"filter": {
"term": {
"processNumber": "11/2014"
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
因此,使用11 /或/ 2014之类的不同内容进行搜索将不会返回匹配.这可以.
但是,如果我将字段定义为not_analyzed,我不能sql LIKE使用match_phrase查询进行类型搜索.
{
"query": {
"match_phrase": {
"processNumber": "11/201"
}
}
}
Run Code Online (Sandbox Code Playgroud)
在这种情况下,搜索11,11 /,/ 2014或2014应返回命中,但它们不会.问题是,如果字段未映射为一个字段,则此查询有效not_analyzed.所以我似乎要么使用其中一个,问题是该字段应该支持不同查询的两个选项,我在这里遗漏了什么?
我有一个问题,需要从elasticsearch获取基于id的doc并使用它来进行另一个查询.这有效,但我不得不两次往返弹性搜索集群.我可以在一个查询中以某种方式执行此操作,例如查询弹性搜索,并将其输出用作另一个查询的输入以避免往返?
如果您不理解这个问题,请告诉我.
我正在尝试使用Elasticsearch Java NodeBuilder Client连接到我的服务器.但是我没有看到任何指定我的服务器地址和端口的选项(就像我们可以在Transport Client中一样使用addNewTransportAddress("serveraddress", port)).如何让Node Client连接到我的服务器?代码如下,我在哪里提到要连接的服务器地址?
//On Startup
Node node = nodeBuilder()
.clusterName("elasticsearch")
.data(false) //No shards allocated; or can set client to true
.client(true) //No shards allocated; or can set data to false
.node();
//Node Client
Client client = node.client();
//Get API
GetResponse response = client.prepareGet("indexname", "type", "id")
.execute()
.actionGet();
System.out.println("----------------Index Output Begin----------------");
System.out.println("Index Name: " + response.getIndex());
System.out.println("Type: " + response.getType());
System.out.println("Document ID: " + response.getId());
System.out.println("Document Version: " + response.getVersion());
System.out.println("Source: " + response.getSourceAsString());
Run Code Online (Sandbox Code Playgroud) 我在Elasticsearch中有一个字段,其值为"PEI.H.02354.01.".当我用querystringas 搜索时
{
"query":{
"query_string":{
"query":"field:PEI.H.02354.01.",
"default_operator":"AND"
}
}
}
Run Code Online (Sandbox Code Playgroud)
然后返回一个结果,这是正确的行为.但是,如果我使用通配符搜索,则不会返回任何结果,例如
{
"query":{
"query_string":{
"query":"field:PEI.H.02354.01.*",
"default_operator":"AND"
}
}
}
Run Code Online (Sandbox Code Playgroud)
该字段是字符串类型并进行分析.下面是创建索引的代码,包括分析器和映射.
{
"settings":{
"analysis":{
"analyzer":{
"number":{
"type":"custom",
"tokenizer":"keyword",
"filter":[
"lowercase"
],
"char_filter":[
"number_filter"
]
},
"diacritical":{
"type":"custom",
"tokenizer":"standard",
"filter":[
"standard",
"lowercase",
"asciifolding",
"nfd_normalizer"
]
}
},
"filter":{
"nfd_normalizer":{
"type":"icu_normalizer",
"name":"nfc"
}
},
"char_filter":{
"number_filter":{
"type":"pattern_replace",
"pattern":"[^\\d]+",
"replacement":""
}
}
}
},
"mappings":{
"testType":{
"_source":{
"enabled":false
},
"_all":{
"enabled":false
},
"_timestamp":{
"enabled":"true",
"store":"yes"
},
"properties":{
"field":{
"store":"yes",
"type":"string",
"index":"analyzed",
"analyzer":"diacritical" …Run Code Online (Sandbox Code Playgroud)