Elasticsearch Version: 5.0.2Elasticsearch einfachen Begriff Abfrage gibt seltsame Partituren
ich bevölkern meine Index mit:
{_id: 1, tags: ['plop', 'plip', 'plup']},
{_id: 2, tags: ['plop', 'plup']},
{_id: 3, tags: ['plop']},
{_id: 4, tags: ['plap', 'plep']},
{_id: 5, tags: ['plop', 'plip', 'plup']},
{_id: 6, tags: ['plup', 'plip']},
{_id: 7, tags: ['plop', 'plip']}
Dann würde Ich mag die max relevanten Zeilen für Tags plop
und plip
abzurufen:
query: {
bool: {
should: [
{term: {tags: {value:'plop', _name: 'plop'}}},
{term: {tags: {value:'plip', _name: 'plip'}}}
]
}
}
, die äquivalent ist (aber ich verwendet, um die ersteren zu debug):
query: {
bool: {
should: [
{terms: {tags: ['plop', 'plip']}}
]
}
}
Dann finde ich wirklich seltsam Partituren:
[
{ id: '2', score: 0.88002616, tags: [ 'plop', 'plup' ] },
{ id: '6', score: 0.88002616, tags: [ 'plup', 'plip' ] },
{ id: '5', score: 0.5063205, tags: [ 'plop', 'plip', 'plup' ] },
{ id: '7', score: 0.3610978, tags: [ 'plop', 'plip' ] },
{ id: '1', score: 0.29277915, tags: [ 'plop', 'plip', 'plup' ] },
{ id: '3', score: 0.2876821, tags: [ 'plop' ] }
]
Hier die Einzelheiten der Antwort ist:
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 6,
"max_score": 0.88002616,
"hits": [
{
"_index": "myindex",
"_type": "mytype",
"_id": "2",
"_score": 0.88002616,
"_source": {
"tags": [
"plop",
"plup"
]
},
"matched_queries": [
"plop"
]
},
{
"_index": "myindex",
"_type": "mytype",
"_id": "6",
"_score": 0.88002616,
"_source": {
"tags": [
"plup",
"plip"
]
},
"matched_queries": [
"plip"
]
},
{
"_index": "myindex",
"_type": "mytype",
"_id": "5",
"_score": 0.5063205,
"_source": {
"tags": [
"plop",
"plip",
"plup"
]
},
"matched_queries": [
"plop",
"plip"
]
},
{
"_index": "myindex",
"_type": "mytype",
"_id": "7",
"_score": 0.3610978,
"_source": {
"tags": [
"plop",
"plip"
]
},
"matched_queries": [
"plop",
"plip"
]
},
{
"_index": "myindex",
"_type": "mytype",
"_id": "1",
"_score": 0.29277915,
"_source": {
"tags": [
"plop",
"plip",
"plup"
]
},
"matched_queries": [
"plop",
"plip"
]
},
{
"_index": "myindex",
"_type": "mytype",
"_id": "3",
"_score": 0.2876821,
"_source": {
"tags": [
"plop"
]
},
"matched_queries": [
"plop"
]
}
]
}
}
also zwei Fragen:
- Warum eine Reihe maching nur eine Abfrage (id 2 und 6) haben eine bessere Punktzahl als eine übereinstimmende zwei (id 1, 5 und 7)?
- Warum können zwei Zeilen mit denselben Tags unterschiedliche Werte haben? (ID 1 und 5)
Habe ich etwas übersehen?
Tags ist nicht_analysiert? – blackmamba
Karte Tags als nicht_analysiert und es wird gut funktionieren – blackmamba
Es funktioniert nicht. Werfen Sie einen Blick auf meinen Kommentar zur ersten Antwort für weitere Informationen. – Gnucki