我正在使用两个自定义分析器,自动完成和一个默认分析器:
{
"analysis": {
"analyzer": {
"autocomplete": {
"type": "custom",
"tokenizer": "whitespace",
"filter": [
"lowercase",
"mystopwords",
"my_stemmer"
]
},
"default": {
"type": "custom",
"tokenizer": "my_tokenizer",
"filter": [
"my_delimiter",
"lowercase"
]
}
},
"tokenizer": {
"myngram": {
"type": "ngram",
"min_gram": 3,
"max_gram": 30
},
"my_tokenizer": {
"type": "pattern",
"pattern": "<>"
}
},
"filter": {
"mystopwords": {
"type": "stop",
"ignore_case": true,
"_lang_": "french"
},
"my_stemmer": {
"type": "stemmer",
"name": "french"
},
"my_ngram_delimiter": {
"type": "word_delimiter",
"preserve_original": false,
"split_on_numerics": false,
"catenate_numbers": false,
"catenate_all": false,
"split_on_case_change": false,
"catenate_words": false,
"generate_word_parts": true,
"generate_number_parts": false
},
"my_delimiter": {
"type": "word_delimiter",
"preserve_original": true,
"split_on_numerics": false,
"catenate_numbers": false,
"catenate_all": false,
"split_on_case_change": false,
"catenate_words": false,
"generate_word_parts": false,
"generate_number_parts": false
}
}
} }
我可以毫无痛苦地使用自动完成分析器:
curl 'localhost:9200/index/_analyze?pretty=1&analyzer=autocomplete' -d 'polo à manches courtes pour femme'
结果是:
{
"tokens" : [ {
"token" : "polo",
"start_offset" : 0,
"end_offset" : 4,
"type" : "word",
"position" : 1
}, {
"token" : "à",
"start_offset" : 5,
"end_offset" : 6,
"type" : "word",
"position" : 2
}, {
"token" : "manch",
"start_offset" : 7,
"end_offset" : 14,
"type" : "word",
"position" : 3
}, {
"token" : "court",
"start_offset" : 15,
"end_offset" : 22,
"type" : "word",
"position" : 4
}, {
"token" : "pour",
"start_offset" : 23,
"end_offset" : 27,
"type" : "word",
"position" : 5
}, {
"token" : "femm",
"start_offset" : 28,
"end_offset" : 33,
"type" : "word",
"position" : 6
} ]
}
正如预期的那样,结果是正确的,但是在执行查询-dsl 时:
curl -XGET "http://localhost:9200/index/_search?pretty=true" -d'
{
"size": 2000,
"fields": ["_id"],
"query": {
"filtered": {
"query": {
"bool": {
"must_not":[
{
"match":{"produitStatus":"inactif"}
}
]
}
},
"filter": {
"and": [{
"query":{
"nested":{
"path":"articleHasAttribut",
"query":{
"bool": {
"must":[
{
"match":{"articleHasAttribut.recherche":"oui"}
}
]
}
}
}
}
}],
"or": [{
"query": {
"text": {
"libelleArticleCatalogue": { "query":search,"analyzer":"autocomplete"}
}
}
}, {
"query": {
"nested": {
"path": "articleHasAttribut",
"query": {
"text": {
"articleHasAttribut.valeur": { "query":search,"analyzer":"autocomplete"}
}
}
}
}
}, {
"query": {
"nested": {
"path": "articleHasAttribut",
"query": {
"text": {
"articleHasAttribut.titre": { "query":search,"analyzer":"autocomplete"}
}
}
}
}
}, {
"query": {
"nested": {
"path": "articleHasAttribut",
"query": {
"text": {
"articleHasAttribut.typeProduit": { "query":search,"analyzer":"autocomplete"}
}
}
}
}
}, {
"query": {
"text": {
"codeArticle": { "query":search,"analyzer":"autocomplete"}
}
}
}, {
"query": {
"text": {
"codeCatalogue": { "query":search,"analyzer":"autocomplete"}
}
}
}, {
"query": {
"text": {
"attributType": { "query":search,"analyzer":"autocomplete"}
}
}
}, {
"query": {
"text": {
"descriptionArticleCatalogue": { "query":search,"analyzer":"autocomplete"}
}
}
}]
}
}
}
,
"facets": {
"Attributs": {
"terms": {
"field": "codeArticle"
}
}
}
}'
我没有得到任何结果:
{
"took" : 54,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"failed" : 0
},
"hits" : {
"total" : 0,
"max_score" : null,
"hits" : [ ]
}
}
所以问题是为什么我的自动完成分析器在不执行任何搜索查询-dsl 的情况下不像第一个请求那样表现