Я запрашиваю следующий индекс эластичного поиска с именем job6, используя оператор $ .get JSON из-за требований к реализации.
{
"took": 0,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 5,
"relation": "eq"
},
"max_score": 1.0,
"hits": [{
"_index": "job6",
"_type": "_doc",
"_id": "2e2ed07786c01e9fd845b62fb86a693a",
"_score": 1.0,
"_source": {
"meta": {},
"file": {
"extension": "txt",
"content_type": "text/plain",
"created": "2020-04-03T11:57:45.673+0000",
"last_modified": "2020-02-27T16:15:27.795+0000",
"last_accessed": "2020-04-03T11:57:45.673+0000",
"indexing_date": "2020-04-14T13:56:51.668+0000",
"filesize": 0,
"filename": "fichero0_borrador.txt",
"url": "file://C:\\TMPM\\carpeta0\\99.Borrador\\fichero0_borrador.txt"
},
"path": {
"root": "4cface21f575d5e5985e4e3889c278a3",
"virtual": "PM/carpeta0/99.Borrador/fichero0_borrador.txt",
"real": "C:\\TMPM\\carpeta0\\99.Borrador\\fichero0_borrador.txt"
}
}
}, {
"_index": "job6",
"_type": "_doc",
"_id": "6f475ff7ac21fc59f4edc34761d09",
"_score": 1.0,
"_source": {
"content": "cadena0 A\n",
"meta": {},
"file": {
"extension": "txt",
"content_type": "text/plain; charset=ISO-8859-1",
"created": "2020-04-14T09:30:20.218+0000",
"last_modified": "2020-04-14T09:46:02.930+0000",
"last_accessed": "2020-04-14T09:46:02.930+0000",
"indexing_date": "2020-04-14T13:56:52.223+0000",
"filesize": 9,
"filename": "fichero0_A.txt",
"url": "file://C:\\TMPM\\carpeta0\\fichero0_A.txt"
},
"path": {
"root": "c073f96a8d16ebb2e604bebd4fe8b40",
"virtual": "PM/carpeta0/fichero0_A.txt",
"real": "C:\\TMPM\\carpeta0\\fichero0_A.txt"
}
}
}, {
"_index": "job6",
"_type": "_doc",
"_id": "7dfb102f2e64e99740a89b1cff7d92a3",
"_score": 1.0,
"_source": {
"content": "cadena1\n",
"meta": {},
"file": {
"extension": "txt",
"content_type": "text/plain; charset=ISO-8859-1",
"created": "2020-04-03T11:56:21.165+0000",
"last_modified": "2020-04-03T12:23:23.872+0000",
"last_accessed": "2020-04-03T12:23:23.872+0000",
"indexing_date": "2020-04-14T13:56:52.254+0000",
"filesize": 7,
"filename": "fichero1.txt",
"url": "file://C:\\TMPM\\carpeta1\\fichero1.txt"
},
"path": {
"root": "7ff4e7b0e0c3172dbd29a23861ab2125",
"virtual": "PM/carpeta1/fichero1.txt",
"real": "C:\\TMPM\\carpeta1\\fichero1.txt"
}
}
}, {
"_index": "job6",
"_type": "_doc",
"_id": "74f0e8c1cccf2f32b4d43673cfdca0",
"_score": 1.0,
"_source": {
"content": "cadena2\n",
"meta": {},
"file": {
"extension": "txt",
"content_type": "text/plain; charset=ISO-8859-1",
"created": "2020-04-03T11:56:30.524+0000",
"last_modified": "2020-04-03T12:23:35.029+0000",
"last_accessed": "2020-04-03T12:23:35.029+0000",
"indexing_date": "2020-04-14T13:56:52.270+0000",
"filesize": 7,
"filename": "fichero2.txt",
"url": "file://C:\\TMPM\\carpeta2\\fichero2.txt"
},
"path": {
"root": "fd0c8ae8a885725cfcaee774c72be43",
"virtual": "PM/carpeta2/fichero2.txt",
"real": "C:\\TMPM\\carpeta2\\fichero2.txt"
}
}
}, {
"_index": "job6",
"_type": "_doc",
"_id": "8d6c56c0448bc4bfa17787923baa9c",
"_score": 1.0,
"_source": {
"content": "cadenaX\n",
"meta": {},
"file": {
"extension": "txt",
"content_type": "text/plain; charset=ISO-8859-1",
"created": "2020-04-14T15:12:56.632+0000",
"last_modified": "2020-04-14T15:34:53.139+0000",
"last_accessed": "2020-04-14T15:34:53.139+0000",
"indexing_date": "2020-04-14T15:35:14.685+0000",
"filesize": 7,
"filename": "fichero_X.txt",
"url": "file://C:\\TMPM\\carpetaX\\fichero_X.txt"
},
"path": {
"root": "f43118a935c6c7ef81ea65307759fc",
"virtual": "PM/carpetaX/fichero_X.txt",
"real": "C:\\TMPM\\carpetaX\\fichero_X.txt"
}
}
}
]
}
используя следующий код. * Использование $ .get JSON является обязательным *
<html>
<head>
<meta charset='UTF-8' />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
<script type="text/javascript">
$(document).ready(function(){
var url = 'http://localhost:9200/job6/_search'
//QUERY A
var datos =
{
"query": {
"match_all": {}
},
"from" : "0", "size" : "2"
}
;
//QUERY B
/*
var datos =
{"query": {
"query_string" : {
"query" : "fichero1.txt",
"default_field" : "file.filename"
}
}
};
*/
//QUERY C
/*
var datos =
{
"query": {
"query_string": {
"query" : "fichero1.txt"
}
}
}
;
*/
//QUERY D
/*
var datos =
{
"query": {
"simple_query_string": {
"all_fields" : true ,
"query" : "fichero1.txt"
}
}
}
;
*/
//QUERY E
/*
var datos =
{
"query":
{ "query_string":
{ "query": "fichero1.txt", "fields": ["file.filename"]
}
}
}
;
*/
//QUERY F
/*
var datos =
{
"query" : {
"match" : {
"file.filename" : "fichero1.txt"
}
}
}
;
*/
var input_jsonString = JSON.stringify(datos);
console.log("input_jsonString=" + input_jsonString);
$.getJSON(url, datos, function (jsonFromFile) {
var output_jsonString = JSON.stringify(jsonFromFile);
console.log("output_jsonString=" + output_jsonString);
}
)
});
</script>
</body>
</html>
Я получаю ответ только на следующий запрос A
var datos = {
"query": {
"match_all": {}
},
"from": "0",
"size": "2"
};
С ответом
output_jsonString = {
"took": 0,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 5,
"relation": "eq"
},
"max_score": 1,
"hits": [{
"_index": "job6",
"_type": "_doc",
"_id": "2e2ed07786c01e9fd845b62fb86a693a",
"_score": 1,
"_source": {
"meta": {},
"file": {
"extension": "txt",
"content_type": "text/plain",
"created": "2020-04-03T11:57:45.673+0000",
"last_modified": "2020-02-27T16:15:27.795+0000",
"last_accessed": "2020-04-03T11:57:45.673+0000",
"indexing_date": "2020-04-14T13:56:51.668+0000",
"filesize": 0,
"filename": "fichero0_borrador.txt",
"url": "file://C:\\TMPM\\carpeta0\\99.Borrador\\fichero0_borrador.txt"
},
"path": {
"root": "4cface21f575d5e5985e4e3889c278a3",
"virtual": "PM/carpeta0/99.Borrador/fichero0_borrador.txt",
"real": "C:\\TMPM\\carpeta0\\99.Borrador\\fichero0_borrador.txt"
}
}
}, {
"_index": "job6",
"_type": "_doc",
"_id": "6f475ff7ac21fc59f4edc34761d09",
"_score": 1,
"_source": {
"content": "cadena0 A\n",
"meta": {},
"file": {
"extension": "txt",
"content_type": "text/plain; charset=ISO-8859-1",
"created": "2020-04-14T09:30:20.218+0000",
"last_modified": "2020-04-14T09:46:02.930+0000",
"last_accessed": "2020-04-14T09:46:02.930+0000",
"indexing_date": "2020-04-14T13:56:52.223+0000",
"filesize": 9,
"filename": "fichero0_A.txt",
"url": "file://C:\\TMPM\\carpeta0\\fichero0_A.txt"
},
"path": {
"root": "c073f96a8d16ebb2e604bebd4fe8b40",
"virtual": "PM/carpeta0/fichero0_A.txt",
"real": "C:\\TMPM\\carpeta0\\fichero0_A.txt"
}
}
}
]
}
Для проверки значения входного запроса и полученного вывода. Я создал переменные 'input_jsonString' и 'output_jsonString', к которым обращаюсь, используя команду 'console.log'.
У меня проблема в том, что я получаю ошибки, все с одинаковыми характеристиками, в следующих типах запросов. В коде указано QUERY B, C, .. F (чтобы проверить код удаления комментариев). Например, для следующего запроса с именем C
input_jsonString = {"query":{"query_string":{"query":"fichero1.txt"}}}
я получаю следующую ошибку:
{"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"request [/job6/_search] contains unrecognized parameter: [query[query_string][query]]"}],"type":"illegal_argument_exception","reason":"request [/job6/_search] contains unrecognized parameter: [query[query_string][query]]"},"status":400}
Хотя ранее я проверял это через Kibana , что все запросы были закодированы правильно и от которых я получаю правильный ответ, все они. Как на изображении запроса C:
Пожалуйста, какую ошибку я совершаю?
Заранее спасибо