我无法在ElasticSearch中获得正确的结果。搜索查询将包含以下文本tower A flat no 1103
。由于我在搜索查询中指定了tower A
,我希望顶部的结果包含tower A
,但ElasticSearch的排序是随机的。以下是我的API响应:-
[
{
"taskId": "TSK40izdmlm4dmo",
"taskName": "Granite Work",
"workBreakDownStr": [
{
"name": "Prabhu Heights",
"_id": "TSKt5s9u90i5exo",
"highlight": true
},
{
"name": "Tower B - 3BHK",
"_id": "TSK3xifvny8eovm",
"highlight": true
},
{
"name": "11th Floor",
"_id": "TSK3hr5cdeqs31s",
"highlight": false
},
{
"name": "Flat no- 1103",
"_id": "TSKesl2nhhgzgg6",
"highlight": true
},
{
"_id": "TSK40izdmlm4dmo",
"name": "Granite Work",
"highlight": true
}
],
"ancestors_combined": "Prabhu Heights | Tower B - 3BHK | 11th Floor | Flat no- 1103 | Granite Work"
},
{
"taskId": "TSK7nubnw3ytrc9",
"taskName": "Granite Work",
"workBreakDownStr": [
{
"name": "Prabhu Heights",
"_id": "TSKt5s9u90i5exo",
"highlight": true
},
{
"name": "Tower A - 4BHK",
"_id": "TSKal1o0u24fdwx",
"highlight": true
},
{
"name": "11th Floor",
"_id": "TSKcxmewckiw68e",
"highlight": false
},
{
"name": "Flat no- 1103",
"_id": "TSKy2brl99xvomr",
"highlight": true
},
{
"_id": "TSK7nubnw3ytrc9",
"name": "Granite Work",
"highlight": true
}
],
"ancestors_combined": "Prabhu Heights | Tower A - 4BHK | 11th Floor | Flat no- 1103 | Granite Work"
},
{
"taskId": "TSKs3squjd1z447",
"taskName": "Masonry Work",
"workBreakDownStr": [
{
"name": "Prabhu Heights",
"_id": "TSKt5s9u90i5exo",
"highlight": true
},
{
"name": "Tower B - 3BHK",
"_id": "TSK3xifvny8eovm",
"highlight": true
},
{
"name": "11th Floor",
"_id": "TSK3hr5cdeqs31s",
"highlight": false
},
{
"name": "Flat no- 1103",
"_id": "TSKesl2nhhgzgg6",
"highlight": true
},
{
"_id": "TSKs3squjd1z447",
"name": "Masonry Work",
"highlight": true
}
],
"ancestors_combined": "Prabhu Heights | Tower B - 3BHK | 11th Floor | Flat no- 1103 | Masonry Work"
},
{
"taskId": "TSK3ps8qgofeius",
"taskName": "Masonry Work",
"workBreakDownStr": [
{
"name": "Prabhu Heights",
"_id": "TSKt5s9u90i5exo",
"highlight": true
},
{
"name": "Tower A - 4BHK",
"_id": "TSKal1o0u24fdwx",
"highlight": true
},
{
"name": "11th Floor",
"_id": "TSKcxmewckiw68e",
"highlight": false
},
{
"name": "Flat no- 1103",
"_id": "TSKy2brl99xvomr",
"highlight": true
},
{
"_id": "TSK3ps8qgofeius",
"name": "Masonry Work",
"highlight": true
}
],
"ancestors_combined": "Prabhu Heights | Tower A - 4BHK | 11th Floor | Flat no- 1103 | Masonry Work"
},
{
"taskId": "TSKgy9przl1vny2",
"taskName": "Tiling Work",
"workBreakDownStr": [
{
"name": "Prabhu Heights",
"_id": "TSKt5s9u90i5exo",
"highlight": true
},
{
"name": "Tower B - 3BHK",
"_id": "TSK3xifvny8eovm",
"highlight": true
},
{
"name": "11th Floor",
"_id": "TSK3hr5cdeqs31s",
"highlight": false
},
{
"name": "Flat no- 1103",
"_id": "TSKesl2nhhgzgg6",
"highlight": true
},
{
"_id": "TSKgy9przl1vny2",
"name": "Tiling Work",
"highlight": false
}
],
"ancestors_combined": "Prabhu Heights | Tower B - 3BHK | 11th Floor | Flat no- 1103 | Tiling Work"
},
{
"taskId": "TSKr2q0t09yooav",
"taskName": "Tiling Work",
"workBreakDownStr": [
{
"name": "Prabhu Heights",
"_id": "TSKt5s9u90i5exo",
"highlight": true
},
{
"name": "Tower A - 4BHK",
"_id": "TSKal1o0u24fdwx",
"highlight": true
},
{
"name": "11th Floor",
"_id": "TSKcxmewckiw68e",
"highlight": false
},
{
"name": "Flat no- 1103",
"_id": "TSKy2brl99xvomr",
"highlight": true
},
{
"_id": "TSKr2q0t09yooav",
"name": "Tiling Work",
"highlight": false
}
],
"ancestors_combined": "Prabhu Heights | Tower A - 4BHK | 11th Floor | Flat no- 1103 | Tiling Work"
},
{
"taskId": "TSKj9gr35kqmi3s",
"taskName": "Water Proffing",
"workBreakDownStr": [
{
"name": "Prabhu Heights",
"_id": "TSKt5s9u90i5exo",
"highlight": true
},
{
"name": "Tower B - 3BHK",
"_id": "TSK3xifvny8eovm",
"highlight": true
},
{
"name": "11th Floor",
"_id": "TSK3hr5cdeqs31s",
"highlight": false
},
{
"name": "Flat no- 1103",
"_id": "TSKesl2nhhgzgg6",
"highlight": true
},
{
"_id": "TSKj9gr35kqmi3s",
"name": "Water Proffing",
"highlight": true
}
],
"ancestors_combined": "Prabhu Heights | Tower B - 3BHK | 11th Floor | Flat no- 1103 | Water Proffing"
},
{
"taskId": "TSKsnc5tydkqoo8",
"taskName": "Water Proffing",
"workBreakDownStr": [
{
"name": "Prabhu Heights",
"_id": "TSKt5s9u90i5exo",
"highlight": true
},
{
"name": "Tower A - 4BHK",
"_id": "TSKal1o0u24fdwx",
"highlight": true
},
{
"name": "11th Floor",
"_id": "TSKcxmewckiw68e",
"highlight": false
},
{
"name": "Flat no- 1103",
"_id": "TSKy2brl99xvomr",
"highlight": true
},
{
"_id": "TSKsnc5tydkqoo8",
"name": "Water Proffing",
"highlight": true
}
],
"ancestors_combined": "Prabhu Heights | Tower A - 4BHK | 11th Floor | Flat no- 1103 | Water Proffing"
},
{
"taskId": "TSK3mha5g3qv7a1",
"taskName": "Inner Plaster",
"workBreakDownStr": [
{
"name": "Prabhu Heights",
"_id": "TSKt5s9u90i5exo",
"highlight": true
},
{
"name": "Tower B - 3BHK",
"_id": "TSK3xifvny8eovm",
"highlight": true
},
{
"name": "11th Floor",
"_id": "TSK3hr5cdeqs31s",
"highlight": false
},
{
"name": "Flat no- 1103",
"_id": "TSKesl2nhhgzgg6",
"highlight": true
},
{
"_id": "TSK3mha5g3qv7a1",
"name": "Inner Plaster",
"highlight": true
}
],
"ancestors_combined": "Prabhu Heights | Tower B - 3BHK | 11th Floor | Flat no- 1103 | Inner Plaster"
},
{
"taskId": "TSKsq196ob3kstz",
"taskName": "Untitled subtask",
"workBreakDownStr": [
{
"name": "Prabhu Heights",
"_id": "TSKt5s9u90i5exo",
"highlight": true
},
{
"name": "Tower B - 3BHK",
"_id": "TSK3xifvny8eovm",
"highlight": true
},
{
"name": "11th Floor",
"_id": "TSK3hr5cdeqs31s",
"highlight": false
},
{
"name": "Flat no- 1103",
"_id": "TSKesl2nhhgzgg6",
"highlight": true
},
{
"_id": "TSKsq196ob3kstz",
"name": "Untitled subtask",
"highlight": true
}
],
"ancestors_combined": "Prabhu Heights | Tower B - 3BHK | 11th Floor | Flat no- 1103 | Untitled subtask"
},
{
"taskId": "TSKqu0vs151cmzm",
"taskName": "Inner Plaster",
"workBreakDownStr": [
{
"name": "Prabhu Heights",
"_id": "TSKt5s9u90i5exo",
"highlight": true
},
{
"name": "Tower A - 4BHK",
"_id": "TSKal1o0u24fdwx",
"highlight": true
},
{
"name": "11th Floor",
"_id": "TSKcxmewckiw68e",
"highlight": false
},
{
"name": "Flat no- 1103",
"_id": "TSKy2brl99xvomr",
"highlight": true
},
{
"_id": "TSKqu0vs151cmzm",
"name": "Inner Plaster",
"highlight": true
}
],
"ancestors_combined": "Prabhu Heights | Tower A - 4BHK | 11th Floor | Flat no- 1103 | Inner Plaster"
},
{
"taskId": "TSKbsyyti2wga85",
"taskName": "Carpenter Work",
"workBreakDownStr": [
{
"name": "Prabhu Heights",
"_id": "TSKt5s9u90i5exo",
"highlight": true
},
{
"name": "Tower B - 3BHK",
"_id": "TSK3xifvny8eovm",
"highlight": true
},
{
"name": "11th Floor",
"_id": "TSK3hr5cdeqs31s",
"highlight": false
},
{
"name": "Flat no- 1103",
"_id": "TSKesl2nhhgzgg6",
"highlight": true
},
{
"_id": "TSKbsyyti2wga85",
"name": "Carpenter Work",
"highlight": true
}
],
"ancestors_combined": "Prabhu Heights | Tower B - 3BHK | 11th Floor | Flat no- 1103 | Carpenter Work"
},
{
"taskId": "TSK0plyn9nbfr26",
"taskName": "Carpenter Work",
"workBreakDownStr": [
{
"name": "Prabhu Heights",
"_id": "TSKt5s9u90i5exo",
"highlight": true
},
{
"name": "Tower A - 4BHK",
"_id": "TSKal1o0u24fdwx",
"highlight": true
},
{
"name": "11th Floor",
"_id": "TSKcxmewckiw68e",
"highlight": false
},
{
"name": "Flat no- 1103",
"_id": "TSKy2brl99xvomr",
"highlight": true
},
{
"_id": "TSK0plyn9nbfr26",
"name": "Carpenter Work",
"highlight": true
}
],
"ancestors_combined": "Prabhu Heights | Tower A - 4BHK | 11th Floor | Flat no- 1103 | Carpenter Work"
},
{
"taskId": "TSKav6rcjbehcpn",
"taskName": "Putti Second Coat",
"workBreakDownStr": [
{
"name": "Prabhu Heights",
"_id": "TSKt5s9u90i5exo",
"highlight": true
},
{
"name": "Tower B - 3BHK",
"_id": "TSK3xifvny8eovm",
"highlight": true
},
{
"name": "11th Floor",
"_id": "TSK3hr5cdeqs31s",
"highlight": false
},
{
"name": "Flat no- 1103",
"_id": "TSKesl2nhhgzgg6",
"highlight": true
},
{
"_id": "TSKav6rcjbehcpn",
"name": "Putti Second Coat",
"highlight": true
}
],
"ancestors_combined": "Prabhu Heights | Tower B - 3BHK | 11th Floor | Flat no- 1103 | Putti Second Coat"
},
{
"taskId": "TSKmctmqqnogjy5",
"taskName": "Putti Second Coat",
"workBreakDownStr": [
{
"name": "Prabhu Heights",
"_id": "TSKt5s9u90i5exo",
"highlight": true
},
{
"name": "Tower A - 4BHK",
"_id": "TSKal1o0u24fdwx",
"highlight": true
},
{
"name": "11th Floor",
"_id": "TSKcxmewckiw68e",
"highlight": false
},
{
"name": "Flat no- 1103",
"_id": "TSKy2brl99xvomr",
"highlight": true
},
{
"_id": "TSKmctmqqnogjy5",
"name": "Putti Second Coat",
"highlight": true
}
],
"ancestors_combined": "Prabhu Heights | Tower A - 4BHK | 11th Floor | Flat no- 1103 | Putti Second Coat"
},
{
"taskId": "TSKvweppvlcqoh6",
"taskName": "Putti First Coat",
"workBreakDownStr": [
{
"name": "Prabhu Heights",
"_id": "TSKt5s9u90i5exo",
"highlight": true
},
{
"name": "Tower B - 3BHK",
"_id": "TSK3xifvny8eovm",
"highlight": true
},
{
"name": "11th Floor",
"_id": "TSK3hr5cdeqs31s",
"highlight": false
},
{
"name": "Flat no- 1103",
"_id": "TSKesl2nhhgzgg6",
"highlight": true
},
{
"_id": "TSKvweppvlcqoh6",
"name": "Putti First Coat",
"highlight": true
}
],
"ancestors_combined": "Prabhu Heights | Tower B - 3BHK | 11th Floor | Flat no- 1103 | Putti First Coat"
},
{
"taskId": "TSKuav7s4x3j0w8",
"taskName": "Plumbing Work",
"workBreakDownStr": [
{
"name": "Prabhu Heights",
"_id": "TSKt5s9u90i5exo",
"highlight": true
},
{
"name": "Tower B - 3BHK",
"_id": "TSK3xifvny8eovm",
"highlight": true
},
{
"name": "11th Floor",
"_id": "TSK3hr5cdeqs31s",
"highlight": false
},
{
"name": "Flat no- 1103",
"_id": "TSKesl2nhhgzgg6",
"highlight": true
},
{
"_id": "TSKuav7s4x3j0w8",
"name": "Plumbing Work",
"highlight": false
}
],
"ancestors_combined": "Prabhu Heights | Tower B - 3BHK | 11th Floor | Flat no- 1103 | Plumbing Work"
},
{
"taskId": "TSK35iyxzo1n48v",
"taskName": "Putti First Coat",
"workBreakDownStr": [
{
"name": "Prabhu Heights",
"_id": "TSKt5s9u90i5exo",
"highlight": true
},
{
"name": "Tower A - 4BHK",
"_id": "TSKal1o0u24fdwx",
"highlight": true
},
{
"name": "11th Floor",
"_id": "TSKcxmewckiw68e",
"highlight": false
},
{
"name": "Flat no- 1103",
"_id": "TSKy2brl99xvomr",
"highlight": true
},
{
"_id": "TSK35iyxzo1n48v",
"name": "Putti First Coat",
"highlight": true
}
],
"ancestors_combined": "Prabhu Heights | Tower A - 4BHK | 11th Floor | Flat no- 1103 | Putti First Coat"
},
{
"taskId": "TSKebpw4u4uj9us",
"taskName": "Plumbing Work",
"workBreakDownStr": [
{
"name": "Prabhu Heights",
"_id": "TSKt5s9u90i5exo",
"highlight": true
},
{
"name": "Tower A - 4BHK",
"_id": "TSKal1o0u24fdwx",
"highlight": true
},
{
"name": "11th Floor",
"_id": "TSKcxmewckiw68e",
"highlight": false
},
{
"name": "Flat no- 1103",
"_id": "TSKy2brl99xvomr",
"highlight": true
},
{
"_id": "TSKebpw4u4uj9us",
"name": "Plumbing Work",
"highlight": false
}
],
"ancestors_combined": "Prabhu Heights | Tower A - 4BHK | 11th Floor | Flat no- 1103 | Plumbing Work"
},
{
"taskId": "TSK8dkyspduz44n",
"taskName": "Outer Plaster",
"workBreakDownStr": [
{
"name": "Prabhu Heights",
"_id": "TSKt5s9u90i5exo",
"highlight": true
},
{
"name": "Tower B - 3BHK",
"_id": "TSK3xifvny8eovm",
"highlight": true
},
{
"name": "11th Floor",
"_id": "TSK3hr5cdeqs31s",
"highlight": false
},
{
"name": "Flat no- 1103",
"_id": "TSKesl2nhhgzgg6",
"highlight": true
},
{
"_id": "TSK8dkyspduz44n",
"name": "Outer Plaster",
"highlight": true
}
],
"ancestors_combined": "Prabhu Heights | Tower B - 3BHK | 11th Floor | Flat no- 1103 | Outer Plaster"
}
]
下面是我使用的查询
const should = [
{
match : {
ancestors_combined : {
query : text,
operator : 'and',
fuzziness : 0,
analyzer : 'ngram_analyzer',
},
},
},
{
match : {
ancestors_combined : {
query : text,
operator : 'or',
fuzziness : 0,
analyzer : 'ngram_analyzer',
},
},
},
{
match : {
ancestors_combined : {
query : text,
operator : 'and',
fuzziness : 0,
analyzer : 'standard',
},
},
},
{
match : {
ancestors_combined : {
query : text,
operator : 'or',
fuzziness : 0,
analyzer : 'standard',
},
},
},
{
match_phrase_prefix : {
ancestors_combined : {
query : text,
analyzer : 'standard',
},
},
},
];
const query = {
bool : {
filter : [
{
term : {
project_id : projectId,
},
},
{
term : {
is_active : true,
},
},
{
term : {
type : _.taskConstants.TYPE.TASK,
},
},
],
should,
},
};
这里我使用的是ngram_analyzer和标准分析器。
settings : {
analysis : {
analyzer : {
ngram_analyzer : {
type : 'custom',
tokenizer : 'ngram_tokenizer',
filter : ['lowercase', 'ngram_filter'],
},
},
filter : {
ngram_filter : {
type : 'ngram',
min_gram : 1,
max_gram : 20,
},
},
tokenizer : {
ngram_tokenizer : {
token_chars : ['letter', 'digit', 'custom'],
custom_token_chars : '-_.,',
min_gram : '1',
type : 'edge_ngram',
max_gram : '20',
},
},
},
index : {
max_ngram_diff : '20',
},
},
我正在搜索一个字段ancestors_combined
,它由字段ancestors
(类型为数组)
ancestors : {
type : 'nested',
properties : {
_id : { type: 'keyword' },
name : {
type : 'text',
fields : {
keyword : {
type : 'keyword',
},
},
analyzer : 'ngram_analyzer',
},
},
},
ancestors_combined : {
type : 'text',
fields : {
keyword : {
type : 'keyword',
ignore_above : 256,
},
},
analyzer : 'ngram_analyzer',
},
我尝试提升某些字段,但仍然没有显示在最前面。有人能帮我指出我做错了什么吗?如果需要任何额外的信息,请告诉我。注意:-当我在搜索查询中只键入Tower A
或Tower B
时,我会得到正确的结果。同样,workBreakDownStr
的响应是字段ancestors
。
1条答案
按热度按时间i7uq4tfw1#
Tldr;
我不确定您做错了什么,但是您在
should
语句中有一个非常复杂的查询。也许你可以试着简化一下?
我已经为您创建了一个解决方案POC
溶液
设置
要搜索
它只会返回